If you are like me, you probably have an aversion against repeated work. My movie library exists of hundreds of files and while preparing for the Raspberry Pi (which is capable of Full HD hardware H.264 decoding) I thought of automating video transcoding. The following how to or small tutorial is how I transcode video to H.264 mp4 for the Raspberry Pi with HandBrakeCLI.
This guide is for Mac OS X Lion but will probably also work on Leopard and Snow Leopard (not tested).
So, here is what I did:
1. Install HandBrake
2. Install HandBrakeCLI
Move HandBrakeCLI to /Applications.
3. Configure a preset in HandBrake
Create a new preset named RPi (or whatever suits you) with command+n with the following settings.
On the video tab, set Format to MP4 file and Video Codec to H.264:
On the audio tab, set Codec to AAC (CoreAudio). I’ve set the Bitrate to 160 but you could set it to a higher value if your sources have higher quality bitrates.
All other values I have left untouched. Experiment with other settings if you like but these worked best for me.
Open AppleScript Editor (hint: it is in /Applications/Utilities) and copy and paste the code below.
Edit the location of Home:Movies to where you want your monitored folder. In my case Home is my second hard drive and Movies is a folder in the root of Home. Also edit the name of the preset if you named it something else then RPi.
After editing save the AppleScript to “~/Library/Scripts/Folder Action Scripts” with an easy identifiable name. I used “HandBrake – Transcode to RPi.scpt”. If the folders do not exist you can create them.
5. Folder Actions Setup
In Finder, right-click on the relevant folder. In the popup menu navigate to Services and in the flyout menu click on Folder Actions Setup.
You will be presented with Folder Actions Setup program and if all went well you will see your AppleScript in the list. Select the script and click on Attach. Make sure the checkboxes are ticked, also the “Enable Folder Actions”. The Folder Action is ready and you can quit the Folder Actions Setup program.
6. Add files
Now, drag some movie files in the folder and watch the magic happen.
Note: The original files will be deleted and will not be moved to Trash so if you want to keep your original files make sure you do not move them into the folder but copy them. You have been warned!
I have transcoded about 180 files in SD quality in about 10 hours on an early 2011 15″ MacBook Pro Core i7.