The Back Room
Bruce

How to Batch Convert with FFmpeg in Windows

byBruce on Oct.21, 2009, under Software

I have really gotten to love FFMpeg and the capabilities it can bring. It is very frustrating for me that it’s not really distributed with some GUI attached, or with some way of compiling it that doesn’t require a computer scientist. I think that most people that could benefit the most from it are media producers, editors, etc. Many of those folks just don’t have the programming background to sort through source files and binaries and understand really what to do. But, if you get it up and running, it’s really a treat.

I have a project that has a bunch of (about 100 so far) video files that I want to make screen captures of and use as thumbnails in my interface. I could go through one by one, but that’s a real pain and not necessary. So, I created a couple batch scripts that would do the conversion for me. The first script just cycles through a directory and feeds each file that fits certain requirements to my second script for processing. In my case, I have a bunch of .mov files that I want to pull frames from. So, the first script is named “startConvert.bat” and is only a few lines long and looks like this:

for %%i IN (*.mov) DO (doConvert.bat “%%i”)
pause

That basically says that I should feed any file that has an extension of .mov to my second batch script, which is named “doConvert.bat” and looks like this:

IF EXIST “%~d1%~p1%~n1.jpg” GOTO exit

@echo ————————— >> “%~d1%~p1%convert.log”
@echo Conversion for %1 started on %DATE% %TIME%  >> “%~d1%~p1%convert.log”

ffmpeg -i “%~d1%~p1%~n1.mov” -r 29.97 -ss 10.000 -an -vframes 1 -qscale 1 -f mjpeg -y “%~d1%~p1%~n1.jpg”

@echo ————– DONE – SUCCESS ———————- >> “%~d1%~p1%convert.log”

:exit
@echo ——————————– >> “%~d1%~p1%convert.log”
@echo “%~d1%~p1%~n1.jpg” already exists >> “%~d1%~p1%convert.log”

This does a few things. It checks to see if the file already exists, and if so, it skips it. It also writes the results of each conversion to a text file so you can see what happened. There isn’t really much error checking in this, but if you’re familiar with batch scripts, you could probably add some to figure out if there were errors or look for other problems. I am creating deinterlaced .jpg files of freeze frames from 10 seconds into my clip. If you see where the file name gets inserted, you can modify the command line with options from here to do whatever you want and copy/name the files whatever you need. You put both of the files above in the directory with your movies and then double click the first one “startConvert.bat” to rip through them all.

I wanted to put a simple script up though that people could quickly grab and use, without trying to sort through bits of forum posts and other nonsense.

:, , , ,

5 Comments for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...