(FFmpeg) How to convert an entire directory/folder?

Before getting into learning how to use all the amazing and powerful filters, let’s learn one more useful trick; converting an entire directory. Whether it’s to convert an entire folder or apply a filter to multiple files, cycling through files is bound to come up in any workflow.  

In the example below, this one-liner will convert all wav files in a folder to mp3:

 $ for i in *.wav; do ffmpeg -i "$i" "${i%.*}.mp3"; done  

Note: This will keep a copy of the wav files while additionally adding new mp3 files to the same folder.

In this example, this one-line will convert all mov files in a folder to mp4:

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

Pretty easy eh? What about adding a filter that every video should have. In this example adding a hue to make every video black and white:

$ for i in *.mov; do ffmpeg -i "$i" -filter_complex "hue=s=0" "${i%.}.mp4"; done

If a one-line isn’t what you require, a bash script can easily be adapted:

for i in *.mov; do 
  ffmpeg -i "$i" -filter_complex "hug=s=0" "${i%.}.mp4";
done

Love FFmpeg? Grab a copy of FFmpeg For Beginners on Kindle or Paperback to learn over 120 ways to master FFmpeg!

buy now on amazon