-
Notifications
You must be signed in to change notification settings - Fork 1
/
supercut
executable file
·34 lines (28 loc) · 1.09 KB
/
supercut
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
#!/bin/bash
set -euo pipefail #strict mode
# this script takes as arguments
# 1 the file to do a supercut of
# 2 a file of start and end times
# (one pair per line, seperated by whitespace,
# arbitrary comments permitted after end)
# 3 output file (out.mkv by default, clobbers)
# the script outputs a file called out.mkv
# (will clobber existing file of same name)
# note that this script is LOSSY, SLOW, and NOT ESPECIALLY WELL-TESTED
infile="$1"
timefile="$2"
outfile=${3:-out.mkv}
tmpdir="supercut.tmp"
mkdir "$tmpdir"
declare -i i
i=0
while read -r from to comments; do
ffmpeg -loglevel error -i "$infile" -ss "$from" -to "$to" "$tmpdir"/"$(printf '%08d' $i)""$outfile" < /dev/null #have to pipe dev null into ffmpeg so it doesn't eat stdin, for some reason.
# encountered unexpected behavior when I tried to use input (fast) ss
# also encountered unexpected behavior when I tried to use -c:a copy
# or lossless video, or almost anything.
# one must always expect the unexpected.
i+=1
done < "$timefile"
( cd "$tmpdir" ; vid-cat "$outfile" ; mv "$outfile" .. )
rm -r "$tmpdir"