View Full Version : how to BATCH ffmpeg in DOC command prompt


Marius Boruch
August 16th, 2012, 02:44 PM
I have problems with BATCH function in ffmpeg; here is what I use for single file and it works OK

VIDEO OK
ffmpeg -i c:\a\videos\358_5308_01.mxf -vcodec copy -acodec copy -y c:\a\converted\358_5308_01conv.m2t
AUDIO OK
ffmpeg -i c:\a\videos\358_5308_01.mxf -map 0:0 -vcodec copy -map 0:1 -acodec copy -y c:\a\converted\358_5308_01conv.wav

but for BATCH conversion I found this script online (all mxf files and ffmpeg are in c:\ location) but the script shows "%%a was unexpected at this time" error message.

for %%a in ("*.mxf") do ffmpeg.exe -i "%%a" -vcodec copy -acodec copy -y "%%~na_conv.m2t"

there must be some easy trick to make this BATCH thing work in DOS. Please help.

Chris Medico
August 16th, 2012, 04:10 PM
Give this a read and see if it helps.

How to Batch Convert with FFmpeg in Windows - The Back Room (http://backroom.bostonproductions.com/?p=378)

Marius Boruch
August 16th, 2012, 04:22 PM
thanks but it produces same error: "%%i was unexpected at this time"

I am not sure it is for DOS

Chris Medico
August 16th, 2012, 04:29 PM
Right click the "ffmpeg.exe" file, select properties and make sure sure you have it "unblocked".

Win7 blocks exe files that don't have a security certificate embedded within.

Chris Medico
August 16th, 2012, 04:36 PM
Also take a read of this and see if it help.

How To: Setup and Use ffmpeg on Windows (http://jonhall.info/how_to/setup_and_use_ffmpeg_on_windows)

Marius Boruch
August 16th, 2012, 04:36 PM
Chris, where to find "unblock" option?

Marius Boruch
August 16th, 2012, 04:59 PM
I did "unblock" function but still same error

Chris Medico
August 16th, 2012, 05:00 PM
Bummer. I'm running out of ideas. I wonder if your antivirus software is causing a conflict.

I can run batches of files here on my machine and its a Win7 64bit setup.

Marius Boruch
August 16th, 2012, 05:06 PM
can you provide simple syntax of running batch?
it runs single conversions OK but there is some catch in syntax of the loop

Chris Medico
August 16th, 2012, 05:31 PM
The info you need is here:

forfiles dos and windows command lne help (http://www.computerhope.com/forfiles.htm)

With Win7 you need to use the "forfiles" command. I don't have my scripts handy. Looks like I wiped them out in the last bit of drive cleaning I did.

Martin Smith
December 23rd, 2012, 10:09 AM
Theres a really good free script based encoder (front end)/(back end) for ffmpeg and x264 over at EZEncoder An awesome ffmpeg based encoder that does it all (http://hypedphoto.com/ezencoder.cfm) Its free and can do all sorts of conversions and is all drag n drop.

Roberto Diaz
December 23rd, 2012, 10:45 PM
I think you have to use %%a if you have this in a .bat file, but if you are typing this on the command line, then use just %a.

Jon Shohet
December 24th, 2012, 07:41 AM
Here's a script that works for me : (in this case remux flv to mp4 but you can change of course to whatever ffmpeg option you want)

I put all the files I want to batch convert into a single folder. Then I drag and drop this .bat file onto a dos window :

for /r %1 %%z in (*.flv) do (
ffmpeg -i "%%z" -vcodec copy -acodec copy "%%~dpnz.mp4"
)

Then I press the "space" key once in the dos window, and then drag and drop the folder containing my files onto to the same dos window, and hit "enter".
command line should read something like this :

C:\Users\user>"C:\pathToScript\script.bat" "C:\pathToFolder\folderWithFilesToEncode"

This script assumes ffmpeg is in system32 folder or has been manually added to PATH