Skip to content

Instantly share code, notes, and snippets.

@mageddo
Last active February 22, 2020 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mageddo/e6606c57a4a125fd95ef23af0a8b40b1 to your computer and use it in GitHub Desktop.
Save mageddo/e6606c57a4a125fd95ef23af0a8b40b1 to your computer and use it in GitHub Desktop.
FFmpeg split and set initial video incrementer
#!/bin/bash
read -e -r -p 'input file? ' in;
read -e -i 'edited/' -r -p 'out dir? ' outDir;
read -e -r -p 'out file prefix? ' out;
read -e -i '1' -r -p 'start counter from which number? ' startCounter;
read -e -i '00:05:00' -r -p 'split size? ' splitSize;
tmpdir=$(mktemp -d)
outDir=$(echo $outDir | grep -o ".*[^/]")
mkdir -p "${outDir}"
echo "> splitting"
ffmpeg -i "${in}" -c copy -map 0 -segment_time "${splitSize}" \
-f segment -reset_timestamps 1 "${tmpdir}/${out}-%03d.mp4"
echo "> updating incrementer"
for f in $tmpdir/*.mp4; do
n=$(echo $f | grep -oP '\K([0-9]{3})(?=\.mp4)');
if [ "$n" = "" ]; then
continue;
fi
fname=$(basename $f)
newN=$(printf "%03d" $(expr $n + $startCounter));
nf=$(echo ${fname} | sed "s/$n/$newN/");
mv "$f" "${outDir}/$nf"
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment