How to batch convert/multiplex any files with ffmpeg

With ffmpeg can you convert and multiplex almost every video file. And as it’s a command line converter can you batch convert all your files at once with a basic windows/dos script. Like convert all your video files to mp4 with custom ffmpeg commands. Convert all video files audio to wav.

Tools:
ffmpeg

Guide:
Download ffmpeg from http://ffmpeg.zeranoe.com/builds/ and choose latest 32bit Static version.

Extract the ffmpeg.exe from the 7z file with 7zip and put it in same folder as your video files.
Create a folder named newfiles in your video folder.
Click image for larger version

Name:	batch0.png
Views:	269
Size:	63.5 KB
ID:	18041

Start notepad and type the following to convert all your video files to mp4 with h264 video and aac audio. See more examples at the bottom of this guide.

Code:
for %%a in ("*.*") do ffmpeg -i "%%a" -c:v libx264 -preset slow -crf 20 -c:a libvo_aacenc -b:a 128k "newfiles\%%~na.mp4"
pause

Now save it, File->Save as, change to All files under Save as type and save it as batch.bat.
Click image for larger version

Name:	batch1b.png
Views:	227
Size:	73.6 KB
ID:	18071

Just double click on the batch.bat to start converting. You will see any errors in the command line box.
Name:  batch3.png
Views: 3164
Size:  50.4 KB

When it’s done just press enter in the command line window.
Name:  batch2b.png
Views: 3049
Size:  45.0 KB

Done!

Batch ffmpeg examples:

Convert all *.avi files to mp4 with h264 and aac audio

Code:
for %%a in ("*.avi") do ffmpeg -i "%%a" -c:v libx264 -preset slow -crf 20 -c:a libvo_aacenc -b:a 128k "newfiles\%%~na.mp4"
pause

Convert *.mkv files to mp4 and just copy the video and audio streams

Code:
for %%a in ("*.mkv") do ffmpeg -i "%%a" -vcodec copy -acodec copy "newfiles\%%~na.mp4"
pause

Convert *.* files to wav audio

Code:
for %%a in ("*.*") do ffmpeg -i "%%a" "newfiles\%%~na.wav"
pause

Multiplex *.avi and *.wav files with same name to avi

Code:
for %%a in ("*.avi") do ffmpeg -i "%%~na.wav" -i "%%~na.avi" -acodec copy -vcodec copy "newfiles\%%~na.avi"
pause

Other tips:
Put ffmpeg.exe in for example C:\ffmpeg and make the newfiles folder under C:\newfiles and you never have to move around the ffmpeg.exe and make new newfiles folder all the time. You just make the batch.bat file in the video folder.
Your batch.bat script should look this then:

Code:
for %%a in ("*.*") do "C:\ffmpeg\ffmpeg" -i "%%a" -c:v libx264 -preset slow -crf 20 -c:a libvo_aacenc -b:a 128k "C:\newfiles\%%~na.mp4"
pause

More ffmpeg examples:

http://ffmpeg.org/trac/ffmpeg/wiki
http://cfc.kizzx2.com/index.php/muxing-audio-and-video-with-ffmpeg/

ffmpeg commands explained:

http://ffmpeg.org/ffmpeg.html