Batch script to convert all avi to mp4 and delete after conversion using HandBrake command line

RarLines picture RarLines · Feb 26, 2014 · Viewed 7.8k times · Source

So easy and cool batch question. Sorry for this ultimate newbie question !

I've a folder which contains hundreds of videos like that:

Video001 - Introduction.avi
Video002 - History of Stack Overflow.avi
Video003 - Before Asking.avi
...
Video999 - Conclusion.avi

I need re-encode all of them with x264 codec. Ffmpeg is very slow so I tried to use HandBrake. There is a command line edition of HB and great default presents. I could write this command for converting only one file with "Normal" present:

HandBrakeCLI.exe -i "Video001 - Introduction.avi" -o "Video001 - Introduction.mp4" -Z Normal

My question: How can I convert all of them in folder and delete after conversion process? Thank you!

Note: If you think ffmpeg is better solution I can give my fav present. Handbrake says about Normal present:

Normal: -e x264 -q 20.0 -a 1 -E faac -B 160 -6 dpl2 -R Auto -D 0.0 --audio-copy-mask aac,ac3,dtshd,dts,mp3 --audio-fallback ffac3 -f mp4 --loose-anamorphic --modulus 2 -m --x264-preset veryfast --h264-profile main --h264-level 4.0

Answer

MC ND picture MC ND · Feb 26, 2014
for %%f in (*.avi) do (
    handbrakecli.exe -i "%%~nxf" -o "%%~nf.mp4" -Z Normal
    del "%%~f"
)

For each avi file, call handbrake with the name and extension of input file and generate an output file with the name of the original file and .mp4 extension