Last active
February 22, 2020 18:03
-
-
Save mageddo/e6606c57a4a125fd95ef23af0a8b40b1 to your computer and use it in GitHub Desktop.
FFmpeg split and set initial video incrementer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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