–Preface, skip to the how-to

I have an archive of thousands of movies living on a disk array. Lots of them are obscure rips of old laserdiscs, VHS, and things that maybe played on Soviet Television. Not exactly ephemeral new movies I can just stream from a modern service. Because I’ve been nursing this collection along for over a decade and trading with others, they’re in a number of different formats- divx, matroska, and others. It’s getting increasingly difficult to work with these formats on modern Mac operating systems. While VLC will happily play them, I like to scrub through my movie collections and extract clips to use in video projections. Mpeg Streamclip used to be my tool of choice and it no longer seems to work in Sierra. Perian, a multi codec package for quicktime, died a sad death long ago. It’s clearly time for me to transcode all my media to mp4.

How to batch transcode with Hazel and Handbrake CLI–

This is where the excellent Hazel folder action tool comes in. I’ve used Apple’s Automator on and off for years and always found it slightly confusing and clumsy. Hazel is refreshingly powerful and simple, and since you can fire off shell scripts with it, you can use it with a number of services. I used Handbrake CLI here for simplicity, but if you wanted to encode something other than mp4, you could probably use ffmpeg.

First, grab Hazel. It’s incredibly useful for automating folder actions and there’s a thousand uses for it. Alongside Better Rename it’s my favorite piece of automation software on mac (Alfred is also very good).

Add Handbrake CLI to your applications folder. I’ve seen other tutorials that recommended putting it in /usr/bin but Sierra wouldn’t let me do that even as superuser. Applications works fine.

In my setup I have a movies folder with a bunch of subfolders and then .avi and .mkv files. I don’t want to move the files out of their folders, becuase a lot of them have subtitle track files too. I just want to encode a same-named mp4 file, toss the old avi or mkv and move on.

hazel screenshot

In Hazel I want to add the folder my movies are in in the left, be it downloads or a movies folder or what have you. In my adjacent rules section the first rule I add is one that scans subfolders and applies the other rules to them as well.

hazel screenshot

Then in my case I made two Handbrake CLI scripts, one for mkv files and one for avi’s.

hazel screenshot hazel screenshot hazel screenshot

Here’s my avi to mp4 shell script if you’d like to copy/paste.

/Applications/HandbrakeCLI -i "$1" -o "${1%avi}"mp4 --preset='AppleTV3'

If you wanted to move the transcoded file to a new folder you could just add a path to the beginning of the output filename. I also picked the AppleTV3 preset from handbrake, but you can open up the Handbrake GUI app and take a look at the different presets and see if there’s another you’d prefer.