0

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.

  • for recursive handling, use `find` with the `-exec` option to specify what to do with each file. That "what to do" could be its own script that converts and removes the file. – L. Scott Johnson Oct 01 '20 at 17:26

1 Answers1

0

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"
L. Scott Johnson
  • 4,213
  • 2
  • 17
  • 28