misc/scripts/cut-video

24 lines
482 B
Plaintext
Raw Normal View History

2020-07-22 14:43:23 +02:00
#!/bin/sh
ts2sec() {
IFS=:; set -- $1
echo $(($1*60*60 + $2*60 + $3))
}
SRC="$1"
START="$2"
STOP="$3"
# Calculate the segment time (in seconds)
SPAN="$(($(ts2sec "$STOP") - $(ts2sec "$START")))"
# Generate an output filename
OUT="$(basename "$SRC" .mkv)-cut.mkv"
# Cut exactly the segment requested into $OUT.
ffmpeg -i "$SRC" -ss "$START" -t "$SPAN" -c copy \
-c:v libx265 -preset slow -crf 23 \
-c:a libopus -b:a 96k -ac 2 -ar 48000 -y -- "$OUT"
ls -lh "$SRC" "$OUT"