Windows – Batch convert *.avi files using ffmpeg

batch fileconversionffmpegwindows

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

Best Answer

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"
Related Question