I'm putting together a script to take .mp4 files organized into folders that described the video (eg. cat) and I'd like to do the following:
- rename them with the folder name and a number
- move the video into a folder named and numbered in the same manner
- parse the video into frames using ffmpeg
I'm posting this here to be a reference for others and to ask about how this could be done better. It works fine but I'm wondering how to make it better.
for dir in /path/to/parent/directory/*; do
cd "$dir" && result=${PWD##*/}
cd video
echo "$result"
a=1
for i in *.mp4; do
dafile="$(printf "_%02d.mp4" ${a})"
dafolder="$(printf "_%02d" ${a})"
newfolder="$result$dafolder"
newfile="$result$dafile"
mkdir "${newfolder}"
mv "${i}" "${newfolder}/${newfile}"
cd "${newfolder}"
ffmpeg -i "${newfile}" -r 30 -f image2 "${newfolder}-\%04d.png"
cd ..
let a=a+1
done
done
I used the following links to figure out a bunch of ideas for the code: