snippets/splitAndShrinkVideo

36 lines
706 B
Plaintext
Raw Permalink Normal View History

#!/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"`
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"
i=$(($i+1))
done
2023-01-01 17:53:22 +01:00
lastduration=`$probecmd "$outfile"`
if [ "$lastduration" == "0.000000" ]; then
rm "$outfile"
fi