reem: script to split files based on a track/chapter list

This commit is contained in:
Iris Lightshard 2024-12-16 20:37:42 -07:00
parent 8e84fdb917
commit d5e9326e2f
Signed by: Iris Lightshard
GPG key ID: 688407174966CAF3

27
reem.sh Executable file
View file

@ -0,0 +1,27 @@
#!/bin/sh
lines=$(cat $1 | wc -l)
l=0
mkdir $1_out
while [ $l -lt $lines ]; do
current=$(cat $1 | sed -n "$(($l+1))p")
next=$(cat $1 | sed -n "$(($l+2))p")
l=$(($l+1))
current_ts=$(echo $current | awk '{print $1}')
if [ $(echo ${current_ts} | wc -c) -lt 6 ]; then
current_ts="00:${current_ts}"
fi
next_ts=$(echo $next | awk '{print $1}')
if [ ! -z "$next_ts" ] && [ $(echo ${next_ts} | wc -c) -lt 6 ]; then
next_ts="00:${next_ts}"
fi
track=$(echo $current |awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}')
echo "$track [${current_ts} - ${next_ts}]"
toarg=""
if [ ! -z "${next_ts}" ]; then
toarg="-to ${next_ts}"
fi
# you can use -c:a copy for less accurate cuts n avoid reencoding
ffmpeg -n -ss $current_ts $toarg -i *"$1"*.mp4 -c:v null -c:a aac -b:a 128k $1_out/"${track}.aac"
done