Brendan Dawes
The Art of Form and Code

Automating movie file conversion to MP4

I’m always keen to try and automate processes I repeat a lot, so this is something I’ve done recently that I find handy for my workflow that allows for automatic conversion of movie files to mp4.

I use Basecamp with my clients, uploading work-in-progress, often involving images and movies. The movies are usually exported frame by frame, composited together in Quicktime then saved out as a .mov. Yet when I want to share this video on Basecamp I would drop it onto Handbrake to convert it to mp4, making it smaller in size, cutting down on upload time and file storage on Basecamp. Saving an mp4 from Quicktime in the first place would take an age to export, plus I prefer to have a high quality version for my own documentation.

I thought there must be a better, more automated way, and after some research discovered that Handbrake has a command line version – HandBrakeCLI – which can be used to convert files from the command line like this:

HandBrakeCLI -i /path/to/source -o ../Desktop/my_output.mp4

I next fired up Automator (I’m on a Mac) and chose New File > Service and added a Run Shell Script action. I then changed the Pass Input option to say "as arguments" and wrote this in the script box:

for f in "$@"
name=$(echo $f | cut -f 1 -d '.')
/usr/local/bin/HandBrakeCLI -i "$f" -o "$name.mp4"

This works through each selected file, strips the filename out without the extension and then converts that file to an mp4 with the default Handbrake settings. On saving this workflow I could now control-click on my Quicktime file, go to Services and choose my Handbrake conversion workflow auto-converting the file into an mp4, much quicker than launching Handbrake, choosing the file etc etc.

Even better though was doing this automatically when a new file is saved into a folder. Using Hazel, I set up a new rule that would run the Automator workflow whenever a new movie file was added, converting my videos to mp4s on the fly.

This might be a little specific to my process but hopefully it may come in handy for you, or at least inspire some other ways of optimising your workflow.