forked from Mecvak/ffmpeg_start_stop_cutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffmpeg_startstop
52 lines (46 loc) · 1.09 KB
/
ffmpeg_startstop
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
48
49
50
51
52
#!/bin/bash
while getopts "b:e:hi:o:s:z:" opt; do
case "$opt" in
b)
begin="$OPTARG"
;;
e)
end="$OPTARG"
;;
o)
output_file="$OPTARG"
;;
h)
echo -e '-b flag is start time - either 00:01:00 or 60 is valid \n-e flag is end time\n-i flag is input file\n-o flag is output file\n-z flag for extra ffmpeg options - between single quotes'
exit
;;
i)
input_file="$OPTARG"
;;
z)
options="$OPTARG"
;;
esac
done
begin=${begin:-0}
end=${end:-0}
converter() {
if [ $(echo "$1" | grep \:) ]
then
hour_to_sec="$((10#$(cut -d\: -f1 <<<"$1") * 60 * 60))"
min_to_sec="$((10#$(cut -d\: -f2 <<<"$1") * 60))"
sec="$((10#$(cut -d\: -f3 <<<"$1") + $min_to_sec + $hour_to_sec))"
echo $sec
else
sec=$1
echo $sec
fi
}
echo "$(converter $end)-$(converter $begin)))"
offset="$(($(converter $end)-$(converter $begin)))"
if [ $offset -lt 0 ]
then
echo 'end time is before begin time - exiting'
exit 1
fi
ffmpeg -i "$input_file" -ss "$begin" -t "$offset" $options "$output_file"