snippets/splitAndShrinkVideo

36 lines
702 B
Bash
Executable File

#!/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"
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"
ffmpeg -y -ss "$from" -to "$to" -i "$fullpath" -s ega "$outfile"
i=$(($i+1))
done
lastduration=`$probecmd $outfile`
if [ "$lastduration" == "0.000000" ]; then
rm "$outfile"
fi