From c067ed87f93a352237b76616724dfa72535e2bed Mon Sep 17 00:00:00 2001 From: gutmet Date: Thu, 30 Jun 2022 09:45:53 +0200 Subject: [PATCH] script to split a single video into multiple shorter videos --- splitAndShrinkVideo | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 splitAndShrinkVideo diff --git a/splitAndShrinkVideo b/splitAndShrinkVideo new file mode 100755 index 0000000..2336604 --- /dev/null +++ b/splitAndShrinkVideo @@ -0,0 +1,35 @@ +#!/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