2022-06-30 09:45:53 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
|
|
echo "USAGE: $0 FILE SPLIT_DURATION_SECONDS"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
fullpath="$1"
|
|
|
|
source fileextensions
|
|
|
|
|
|
|
|
outprefix="$dir/$filename"
|
|
|
|
outext=".mp4"
|
|
|
|
|
|
|
|
splitduration="$2"
|
|
|
|
probecmd="ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1"
|
|
|
|
|
2023-01-01 17:53:22 +01:00
|
|
|
duration=`$probecmd "$fullpath"`
|
2022-06-30 09:45:53 +02:00
|
|
|
n=`echo $duration $splitduration | awk '{print int($1/$2)+1}'`
|
|
|
|
|
|
|
|
i=0
|
|
|
|
while [ $i -le $n ]; do
|
|
|
|
from=$(($i*$splitduration))
|
|
|
|
to=$(($from+$splitduration))
|
|
|
|
outfile="$outprefix$i$outext"
|
2023-01-01 17:53:22 +01:00
|
|
|
ffmpeg -y -ss "$from" -to "$to" -i "$fullpath" -s vga "$outfile"
|
2022-06-30 09:45:53 +02:00
|
|
|
i=$(($i+1))
|
|
|
|
done
|
|
|
|
|
2023-01-01 17:53:22 +01:00
|
|
|
lastduration=`$probecmd "$outfile"`
|
2022-06-30 09:45:53 +02:00
|
|
|
|
|
|
|
if [ "$lastduration" == "0.000000" ]; then
|
|
|
|
rm "$outfile"
|
|
|
|
fi
|