-
Notifications
You must be signed in to change notification settings - Fork 1
/
autocut.sh
47 lines (36 loc) · 1.03 KB
/
autocut.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Cut videos using ffmpeg
# Usage: autocut filename timestamp1 timestamp2 timestamp 3 ... (timestamp : hh:mm)
echo "$# parameters found"
IN=$1
START="00:00"
#Getting end of video by it's duration
END=$(ffmpeg -i $IN 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,//)
count=0
#To get: filename without extenstion
base=$(echo $IN | sed 's/\.[^.]*$//')
#To get: file extension
ext=$(echo $IN | sed 's@.*\.@@')
echo "base: $base ; ext: $ext"
if [ $# -gt 1 ]; then
echo "Going to make some good cuts. Hang on..."
else
echo "Enter in this format : autocut filename hh:mm hh:mm ..."
exit 1
fi
makeTheCut(){
newfilename=$(echo "cut_${count}_${base}__${1}_${2}.${ext}")
echo "Making #$count cut : $1-$2"
echo "Creating new file : $newfilename"
ffmpeg -i $IN -ss $1 -to $2 -c copy $newfilename
}
echo "Going to make some cuts in this $END long video"
count=2
lastcut=$START
while [ $count -le $# ]; do
makeTheCut $lastcut ${!count}
lastcut=${!count}
count=$[$count+1]
done
#one more cut for last clip till the end
makeTheCut $lastcut $END