Bulk Re-Encoding Home Videos with Handbrake and Iron Python

Recently Scott Hansellman posted an entry describing his IJW experience recording videos from his digital camcorder to his Windows 7 PC using some of the Windows Live applications. Spurred on by his example I extracted a few hours of footage from some digital tapes I’d been meaning to back up for ages, also with great success. Except that the resulting videos were bloated AVIs. Using Handbrake and Iron Python I was able to cook up the following script to bulk-encode a directory of videos. I expect you could do something similar with the command-line version of Expression Encoder too.

import System
from System import *
from System.IO import *
from System.Diagnostics import

for s in DirectoryInfo(“D:\path\to-your\family\videos\”).GetFiles(”.avi”): 
    arg = String.Format(‘-i “{0}” -t 1 -c 1 -o “{1}” -f mp4 -w 720 –loose-anamorphic  –detelecine –decomb -e x264 -q 20 -a 1,1 -E faac,ac3 -6 dpl2,auto -R 48,Auto -B 160,auto -D 0.0,0.0 -x b-adapt=2:rc-lookahead=50 -v 1’, s.FullName, “D:\output\location\forvideos\” + s.Name.Replace(“.avi”, “.mp4”))
    print arg
    proc = Process.Start(“C:\Program Files (x86)\Handbrake\HandBrakeCLI.exe”, arg) #path to handbrake goes here