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.
October 28th, 2009 on 9:33 am
Thanks for the article. I have also come to like ffmpeg. You can make even more flexible scripts with ffmpeg using a scripting language like biterscripting. Feel free to resource the script posted at http://www.linuxquestions.org/questions/programming-9/a-personal-bash-ffmpeg-batch-script-wip-718990/#post3508264 . Some of your readers may find it useful.
Keep up the good work.
Randi
October 29th, 2009 on 7:31 am
Just wanted to post some resources for getting compiled ffmpeg Windows binaries. The Binary release of ImageMagick comes with a compiled ffmpeg: http://www.imagemagick.org/script/index.php
Also, the WinFF project on Google Code has a simple front end for ffmpeg. I believe you also get the compiled binary with this download: http://code.google.com/p/winff/
December 29th, 2009 on 10:16 pm
check out iConvert
http://sourceforge.net/projects/iconvert/
It is NOT batch. but it ships with ffmpeg compiled and DOES have a nice single file GUI.
And just for the record, I program both Unix and Windows machines for a living and the last thing I have time to be bothered with is compiling source for a utility. It’s a waste of time in addition to being a pain since they don’t support the standard windows environment (VC++) and they want me to set up all the Unix tools on my Windows box. Yeah right. They are just too lazy to make binary packages. But that’s ok, open source lets the iConvert guys do it for us. Now we just need some batch capability added.
December 29th, 2009 on 11:40 pm
Looking some more, found WinFF for batch UI on top of ffmpeg.
http://winff.org/html_new/
September 4th, 2010 on 10:59 am
Thanks for the script! First off I don’t know how to program but I got this to work. However it only worked for me using Windows 7 when I removed the quotation marks.
For example, instead of;
IF EXIST “%~d1%~p1%~n1.jpg” GOTO exit
I put
IF EXIST %~d1%~p1%~n1.jpg GOTO exit
Like I said, I could be missing something here. FYI