Camera Icon

Got an event that needs shooting?  I've covered multiple events for marathon-photos.com and can capture the scenes & emotions that make your event unique.

Some samples of my own work are at Digital Formula on Flickr.

Wand Icon

Do you or your business need a website but you're unsure where to start?  Get in touch now and we'll get it sorted.

I focus on usable functionality & can setup smaller sites using Wordpress within hours of the order being placed.  Magic!

Globe Icon

So, you've already got a website but need help managing it?  I can help you.

Don't worry about knowing every single detail.  I'll find out the most important stuff and work with you to reach your goal, not someone else's.

said on twitter: LOL spammers really do bank on the ignorance of their targets huh? A file with a .jpg.exe extension ... really? http://t.co/0TgobjQc

 
Short URL
Warning: This article is older than 180 days and may contain inaccurate information.  Please use the information below at your own risk.

Running HandBrakeCLI from Hazel

Recently I've been working on some video I shot back in 2009 while in Whistler, Canada on a mountain biking trip.  I've been exporting them as fairly standard .AVI files because that produces good results but I've recently started adding them into my iTunes library so I can watch them on my Apple TV.  I use HandBrake to convert them to .M4V files which can then be imported into iTunes.  This is a manual process, though, so I set about trying to automate it without having to get my video editing program to export to .M4V (the results weren't very good for some reason).

Hazel

Using Hazel from NoodleSoft, I've setup some rules so that when a file of a particular type appears in a selected folder, it runs a Bash script to convert the video and put it into ~/Movies/iTunes.  Hazel isn't free but is worth every cent of the $21.95 USD that I paid for it.  Anyway, if you've got Hazel you'll probably know how to add a folder rule so I won't go into that here, although the screenshot below should be all you need.  Here's the script I run from Hazel.

FILEIN=$1
FILEOUT=`echo "$FILEIN" | awk -F. '{ for (i=1;i<NF;i++) printf $i"."; printf "m4v"}'`
HandBrakeCLI --preset "AppleTV 2" --input "$FILEIN" --output "$FILEOUT"
mv "$FILEOUT" ~/Movies/iTunes/
mv "$FILEIN" ~/.Trash/

Important note: I've just noticed that the Syntax Highlighter plugin kinda breaks the code if it has certain characters in it.  If you're going to copy the script above, change &lt; to the < symbol.

And here's a screenshot of how my Hazel rule's configuration looks.

Hazel rule
Hazel rule to run HandBrakeCLI

That script will set a variable called FILEIN to the name of the file being processed, set a variable called FILEOUT to the same filename but with the extension changed to "m4v" without the extension then, using those variables, run HandBrakeCLI to convert the video using the built-in preset called "AppleTV 2".  The processed video is then moved to the Movies/iTunes folder in my home directory and the source file is moved to the trash.  Note that the file isn't deleted per se, just moved to the trash.  I might want it back later, who knows ...

HandBrakeCLI

The second part, of course, is that you need HandBrakeCLI before the script above will work.  I've got HandBrakeCLI in ~/_Applications but you can put it anywhere.  Don't forget to specify the full path to HandBrakeCLI unless you add the directory name to your PATH environment variable.  HandBrakeCLI is in my PATH so I haven't specified it above.

The Results

So what happens?  Once a file had finished exporting into the appropriate folder, Hazel realises it's there and runs the script that calls HandBrakeCLI.  The command line options specify that the video should be output in a format that's compatible with Apple TV, and therefore iTunes.  I could use the iTunes "Automatlcally Add to iTunes" folder but I've decided not to at this point.

I've got this setup on my Mac Mini server and it just sits there, patiently waiting for the .AVI files to appear in the appropriate folder.  Easy.

» Tags: handbrake, handbrakecli, hazel, convert video
DigitalFormula is an experiment in HTML5 and CSS3 design by Chris Rasmussen, an amateur/casual designer based in Melbourne, Australia. -37.813611 144.963056