Batch converting multiple video formats in nested directories

713 views Asked by At

I'm running Arch/Gnome and am trying to convert a few hundred gigs of family videos from various formats (mov, wmv, mkv, avi mainly, but a few curveballs too) into trusty mp4s.

My scripting knowledge is strictly amateur, so far I have;

for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done

That works fine for one directory. There are hundreds. I'd like to replace that one-liner with something more encompassing that I can just run and go to bed.

Wish list;

  • run recursively

  • convert from mov, wmv, mkv and avi without having to run separate scripts

  • delete old file upon successful completion

  • keep the same file name

  • if it finds an error, just skip the file and keep going - don't stop the process

Any help with any and/or all of these bits to cobble something together that'll work would be most appreciated.

1

There are 1 answers

0
L. Scott Johnson On

For any sort of recursion like this, your first option should be to try find, as in:

find . \( -name \*.avi -o -name \*.mov -o -name \*.wmv -o -name \*.mkv \) \
    -exec convertanddelete {} \;

with the script "convertanddelete" being:

i=$1
ffmpeg -i "$i" "${i%.*}.mp4" && rm "$i"