Skip to content

Instantly share code, notes, and snippets.

@mageddo

mageddo/ffmpeg-splliter.sh

Last active Feb 22, 2020
Embed
What would you like to do?
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