Handbrake CLI Encoding
Ran into a bit of an interesting problem earlier today – a co-worker asked me how to go about encoding a folder of video for his iPod Touch. I immediately turned to Handbrake (being the open-source encoder of choice for OS X), and came to the realization that you have to add each file individually to the queue. Obviously this would not do, so I turned to google, and it seemed as though no one else out there had a solution, so I figured I’d post my hackish solution to the problem here.
First thing you’ll want to do is grab the Handbrake CLI Application – you can grab it here: http://handbrake.fr/downloads2.php
Now, you’ll want to open up a Terminal and make sure all the video files you want to encode are in a folder, and I’d recommend making a destination folder for the encoded videos. Once you’ve got all that set up, just copy and paste this script into a file (call it whatever you want, I called mine convert.sh).
#!/bin/bash
#
# Your configuration stuff should go here - replace these with whatever you want
SRC=./SOURCE_FOLDER/
DEST=./DESTINATION_FOLDER/
DEST_EXT=mp4
HANDBRAKE_CLI=/Applications/HandBrakeCLI
PRESET="iPhone & iPod Touch"
#
# The meat of the script
for FILE in `ls $SRC`
do
filename=$(basename $FILE)
extension=${filename##*.}
filename=${filename%.*}
#
$HANDBRAKE_CLI -i $SRC/$FILE -o $DEST/$filename.$DEST_EXT --preset="$PRESET"
done
You’ll want to chmod this file:
chmod +x convert.sh
Then just run the script and away you go – go get some coffee, or lunch, or dinner, this is going to take a while.
Note: I had to add # to blank lines because wordpress was messing up the formatting. Feel free to remove them at your own leisure.