Sep 12, 2010

Automatically convert AVI to MP4

Posted by Knick

I have ordered my new Apple TV and while I wait the 3ish weeks for it to arrive I have been working to get my Movies library converted from AVI to a nice apple friendly MP4 format. I did a bunch of searching and exploring and found the best solution was to use the HandBrake Command Line Interface and run a batch process through the terminal on my entire movies directory and convert all my files without individual file interaction.

What the following process will do is scan the "source directory" for all AVI files and one by one re-encode them from AVI to MP4. This is a timely process but completely unmanaged as once you get the files in the proper source directory and start the batch process you can walk away.

I have started the batch on my AVI directory of 204 items and am waiting for the final results. The files that have been converted thus far have been perfect.

Follow the process below to run the script:

Download the HandbrakeCLI from here

Place the HandBrakeCLI file in the "Source Directory" where you have the movies you want to convert.

Create a new directory for the destination files to go

Copy and paste the following lines into a terminal window changing the source and destination directories to match your directory structure.

cd "$sourcedir"
for i in *.avi; do
./HandBrakeCLI -i "$i" -o "$destdir/${i%.*}.mp4" --preset="Normal"