2016年8月20日 星期六

A note to batch convert using ffmpeg under windows 7

I was trying to compress my recordings from the 2015 NCKU Wind Band Camp to save space. I choose the ffmpeg to do the job because it seems quite efficient and the format is pretty standard. (The Any Video Coverter just don't work, some weird snapshot problem ketp hunting me)
Since the ffmpeg is a command line tool without gui, the batch script conversion uses the .bat file that can be found easily via google, e.g. here, here and here.
for %%a in ("*.mov") do (
    ffmpeg -i "%%a" -c:v libx264 -c:a aac -b:a 128k "output\%%~na.mp4"
)
pause
Here, for all matches of .mov file, the batch variable %%a (double percentage sign %% for batch, % for command line) is fed into ffmpeg. The encoder for video is assigned to be 264  -c:v libx264 with audio codec -b:a aac  and audio bitrate -b:a 128k of 128K. The %%~na means "Expands %%a to a file name only", which is defined in the For loop tutorial of m$ command line.