Convert avi’s, mkv etc to the iphone

Handbrake is amazing with active development and a great community. When I wanted to transfer a bunch of lectures to iphone/ipod touch format, I faced the time-consuming challenge of converting a hundred files using the Handbrake gui and figuring out the complicated set of options for HandbrakeCLI — their nightly build standalone.

So, here is what I did:

I assume you have the Handbrake gui installed, but not the binary. Go to Handbrake http://build.handbrake.fr/ and get the latest CLI executable for your operating system and put it in a good place, preferably in your path.

Next, you want to make use of the excellent presets in the gui of Handbrake, use the ruby file manicure.rb to get the settings you need. (http://trac.handbrake.fr/browser/trunk/scripts/manicure.rb). Make sure you have the plist gem installed and then you can run.


bonhoffer Tim$ ./manicure.rb -rH > presets

In presets, I found the code I wanted, which I then put in ruby code of my own:


#! /usr/bin/ruby

# handbrake converts all files automatically for the ipod, nice

Dir.glob("*.avi").each do |filename|
  correct_fn = filename.sub(/s/,'-') # let's take out spaces from our filenames 
  File.rename(filename,correct_fn)
  # change the output file name to an mp4 
  new_file_name = correct_fn.sub(/avi$/,'mp4')
  # now it is time for business
  system("HandBrakeCLI -i #{correct_fn} -o #{new_file_name} -e x264 -q 20.0 -a 1 -E faac -B 128 -6 dpl2 -R 48 -D 0.0 -f mp4 -X 480 -m -x cabac=0:ref=2:me=umh:bframes=0:subme=6:8x8dct=0:trellis=0")
end

It is running in the background right now. No silly, clickity, click, click of the gui.

Leave a Reply