misc/scripts/cut-video
rnhmjoj b2ea2c0bd9
scripts/cut-video: fix for octal numbers
Fix for the idiotic design that a number with a leading zero must be
octal
2022-11-16 01:10:58 +01:00

24 lines
494 B
Bash
Executable File

#!/bin/sh
ts2sec() {
IFS=:; set -- $1
echo $((${1#0}*60*60 + ${2#0}*60 + ${3#0}))
}
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"