Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to convert 20+ .avi files in a batch using ffmpeg.

I've got the following

@echo off.

for file in *.avi
do
   ffmpeg -i "$file" -s 640x480 -vcodec msmpeg4v2 "'basename "$file" .avi'.mpg';
done

in my .bat file but it does not work. How can I make it work under Windows OS. Oh, and yes all the files are in the same folder.

The error message I get:

File was unexpected at this time

share|improve this question
    
And what exactly does not work about it? –  slhck Sep 5 '12 at 19:32
    
If you can point me how to get the error message since the cmd disappears very fast, I will be able to tell you what I'm having problem with. –  Darius Sep 5 '12 at 19:37
    
You should be able to just open a command window before (Start » Run… » cmd) and then run the batch file using its full path from there. What do you actually want to do with the videos? What kind of videos are these? Do you just need to move them to an MPG container? Or do you need to resize them? Or do you specifically need the msmpeg4v2 codec? –  slhck Sep 5 '12 at 19:42
    
The files are taken off a DVR and are over 1GB 5 minutes clips. Yes the DVR software is pathetic at compression. The codec works since it takes 1GB files to roughly 7MB files which are more manageable. And when trying to run that batch I get "File was unexpected at this time" message. –  Darius Sep 5 '12 at 19:50
    
I see. If you don't care about the resulting video codec and container, I'd suggest to use x264 as an encoder instead, which results in much better quality than MPEG-4. The command would be something like ffmpeg -i input.avi -c:v libx264 -crf 23 -s 640x480 output.mp4 where the CRF value sets the quality (less is better, more is worse, sane values from 19 to 24). See also: Convert old videos to have smaller sizes and What parameters should I be looking at to reduce the size of a .MOV file? –  slhck Sep 5 '12 at 19:55

1 Answer 1

up vote 8 down vote accepted

Your batch file is not in the correct format for a Windows bat script. Instead your script looks like it was intended for Linux. You will need to change the script to use a for loop that is supported by the Windows Shell.

Below is an example of how to accomplish this task by using a windows for loop. Just put the below line in your batch file and move the script to the same directory as the avi files, then run it.

for %%A IN (*.avi) DO ffmpeg -i "%%A" "%%A.mpg"
share|improve this answer
    
With this I get [NULL @ 000000000037e360] Unable to find a suitable output format for 'outputfile.avi.mpg;' outputfile.avi.mpg:: Invalid argument –  Darius Sep 5 '12 at 20:04
1  
Need to remove that semi-colon from the end of the line –  Brett Sep 5 '12 at 20:18
    
Yep, it did work. Thanks –  Darius Sep 5 '12 at 20:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.