Wednesday, July 11, 2012

Batch convert videos to MP4 - I've done a ton of work so why should you?

Using HandbrakeCLI to create MP4



Both of these use Handbrakecli.exe which is Handbrake's command line interface bundled with Handbrake when you install it. Handbrakecli.exe is, as you might guess, used in the command line (or console, or bash depending on your system).

1. To rip a DVD (or video file) and compress it to MP4:
HandbrakeCLI.exe -i d:\video_ts\ -o videofile.mp4 -b 1200 -B 128 -v -O -d

Explanation starting at the beginning:

Handbrakecli.exe tells the computer to run handbrakecli.exe based on all of the options that follow. NOTE:if you are not in the folder that contains handbrakecli then you need to put in the full path to it - something like "c:\Program Files (x86)\Handbrake\handbrakecli.exe"

-i [options] is the input video/device/folder

-o [options] is the output video file (mp4)

-b [options]is the video bitrate. 1200 is large enough for good quality video. My low quality encodes use -b 800 and sometimes -w 320 which sets the width of the video to 320 (SD is 720 and HD is 1080 or 1440)

-B [options] is the audio bitrate. 128 is CD quality.

-v is...I can't remember

-O optimizes the video for online streaming - it lets you load the beginning of the video before the other parts of the video. Think YouTube with it's loading bar. BTW that is a capital O as in ho ho HO <--

-d deinterlaces the video. Old home movies and some other SD sources usually need this. I use it as needed.


2. Here's a LIFE SAVER I came across and retooled for my collection.
To convert an entire collection of .avi (or other file types) files to .mp4 you can create and run this batch file:

FOR /F "tokens=*" %%G IN ('DIR /B /S *.avi') DO "C:\Program Files\Handbrake\HandbrakeCLI.exe" -i "%%G" -o "%%G".mp4 -b 1200 -B 128 -v -O -d && DEL "%%G"

To use this, open a notepad document, paste the text above into it and then save as converttomp4.bat. Move the .bat file to the folder where the files reside and then run it (double click). WARNING: THIS WILL DELETE THE ORIGINAL FILE!

The explanation of this is too much for here. The main thing you need to know is that where it says *.avi tells the computer to go (loop) through all of the .avi files in the folder and then DO everything after the word DO. %%G is the variable which carries the name of the current file it is working on so after && you can see it says DEL %%G. This deletes the current file after it is converted.


Other stuff:

For a long time I resisted using Handbrake because of it's Apple slant but, since the Bassett Channel, I have used it almost exclusively for my video conversions. Mind you, this is only for converting TO MP4 which is the current trend in compressed quality videos. The phrase 'current trend' is what inspired me to share the information above because I am in the process of converting MY ENTIRE digital video library over to MP4 and I thought others might like to know how I'm doing it. So here you go.

handbrakecli is Handbrake's Command Line Interface and, for some reason, it rips, converts, and compresses faster than just about anything else I've used. Not only that but it gives you as much or as little control over the conversion as you might want/need. The handbrake UI didn't work for me because the presets weren't exactly what I was looking for and, rather than navigate all of the menus and try to figure out what "Optimized for viewing online" meant I just went to the core of the system and have been much happier...but that doesn't mean you will be...

In any case, I hope this helps all you videophiles out there and, again, let me know if you've got questions or need any help.

Richie