10

I've been trying to convert entire folders of files using ffmpeg for a long time now. I've searched the web, found various answers, but none that helped me. Currently I'm using multiple instances of ffmpeg to convert more than one file at a time. But it's very time consuming and annoying to type in everything all the time, even with copy/paste.

To simplify my current code it would look something like this. I specify the input file and the output format (+ various settings):

 ffmpeg -i "EXAMPLE.avi" newEXAMPLE.mp4

But what I would like is a single instance of ffmpeg to convert all files in a specific folder to a new format and for the files to keep their original name.

example1.avi > example1.mp4

example2.avi > example2.mp4

example3.avi > example3.mp4

and so on...

PS. I'm a bit new to these kind of things, so I'd much appreciate an explanation with your answer, so I can understand and learn. Thank you!

Ash_dog
  • 101
  • 1
  • 2
  • 5
  • I believe this is what you're looking for https://stackoverflow.com/a/74585087/11814361 This works for videos in subdirectories as well :) – Joel Mar 30 '23 at 18:59

3 Answers3

17
for /f "tokens=1 delims=." %a in ('dir /B *.avi') do ffmpeg -i "%a.avi" "%a.mp4"

This is for cmd window usage, if you want to use it in the batch script, than double all percent signs. You have run it in directory where your videos reside.

j08691
  • 204,283
  • 31
  • 260
  • 272
user2956477
  • 1,208
  • 9
  • 17
9

If you have multiple periods in your file names, you can use this method instead:

for /r C:\path\ %a in (*.avi) do ffmpeg -i "%a" "%~pa%~na.mp4"

Just edit "C:\path\" as necessary.

Dominic Mason
  • 307
  • 3
  • 8
9

In order to make ffmpeg batch encoding easier for Windows users, I developed this free open-source application using .NET/C#. I would like to include it here as an addtional choice to make things easier for some Windows users who may not be so familiar with command-line operation.

https://sourceforge.net/projects/ffmpeg-batch

Eibel
  • 460
  • 5
  • 7
  • Even with being very familiar with ffmpeg, this is great! It seems to be faster than doing the same thing by command line too, for whatever reason. – Ben Oct 28 '20 at 20:51
  • Well, that's surprising :) – Eibel Oct 29 '20 at 22:58