โ€“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.