Tuesday, September 13, 2011

Batch converting with ffmpeg in Windows

 

As mentioned in my earlier post, ffmpeg is the best tool to convert media files. However sometimes you need to convert a collection files in one go. Of course you can use various gui tools for ffmpeg, but I like to  keep things simple (or complicated, depending on the context).

avs, converter, s icon

Basically ffmpeg can only process 1 file at a time from the command line. Linux/Mac users have powerful bash script at their disposal, but do not underestimate Windows Smile

You probably already have a batch file to convert a single file (which contains all the required parameters for ffmpeg). What we need to do is add an additional batch file which will call “converting” batch file.

So, say you want to convert all .mov files in a folder to .mp3. Let’s start by our converting batch file.

convert-to-mp3.bat

IF EXIST "%1.mp3" GOTO exit

@echo Conversion for %1 started on %DATE% %TIME%
ffmpeg -b 128k -i %1 %1.mp3

:exit
@echo %1.mp3 already exists

What does it do: Checks if output exists, if not then converts the input file to .mp3 using ffmpeg.

Next step is to create the batch file which will call the above batch file.

Startconvert.bat

for %%i IN (*.mov) DO (convert-to-mp3.bat "%%i")
pause

As you can see this is a simple for loop calling your converting batch file.

To just convert all the .mov files to mp3, start startconvert.bat and you will be fine.