Paul Kiddie

Batching video transcodes with Handbrake (Windows)

February 22, 2010

I keep all my media in a central location on a network store but I want to be able to play it on my iphone when I’m away without network connectivity. Most of the content is avi/divx/xvid which the iphone does not play natively.

Handbrake is a really slick transcoder which converts a wide number of video formats to those compatible with mobile devices. It offers a number of built-in profiles for many mobile devices, including the iphone, and comes as UI or command line interface.

Here’s a quick and dirty batch script for Windows which processes a given folder (this assumes you installed Handbrake into the default directory):

FOR /F "tokens=\*" %%G IN (‘DIR /B /S \*.avi’) DO "C:\\Program Files\\Handbrake\\HandBrakeCLI" -i "%%G" -o "%%G".mp4 —-preset="iPhone & iPod Touch"

Copy this into a .bat file in the root of the media folder you wish to transcode the media from. This script will iterate through all the .avi files in the folder, calling Handbrake, and creating an .mp4, suitable for playback on the iphone/ipod touch.

You can customise the batcher to suit, replacing *.avi in the DIR part of the batch file (which provides the input to drive Handbrake) with the type of media file you want to deal with, or replacing the --preset argument with any of those mentioned in the Handbrake wiki (there are profiles for most common devices, including Xbox 360, PSP, PS3, AppleTV etc). Great thing is, I can run the script and leave the PC whirring away overnight


👋 I'm Paul Kiddie, a software engineer working in London. I'm currently working as a Principal Engineer at trainline.