
It uses the free command-line interface of Handbrake called HandbrakeCLI, and is able to convert all videos from specified extensions (ex. avi and mkv) to something that is a bit more widely supported (ex. MP4). All you have to do is point it to a directory and it will start converting all matching videos one-by-one.
How does it work? This is (kind of) a step-by-step walkthrough of how the code processes files if you’re using it without any reconfiguration. You can, of course, tailor it a bit more to your needs.
1. The script looks at a drive called 'Macintosh HD:Users:Tara.Brady:Movies' (you will need to point it to your own folder location) for any video files that have an extension of AVI or MKV (it even looks recursively through all subfolders), and also makes sure that the video has no label colour assigned yet. You’ll find out why the label colour thing is important in the next step.
2. It loops through all of the files it found, and before it begins processing it sets the label colour of the file to grey. That way if you run multiple instances of this at the same time it will not process the same file twice. If you do run this multiple times, however, it only runs one instance of Handbrake at a time.
3. It now runs the HandbrakeCLI using a set of parameters that I’ve found to work well using Front Row. You can configure the parameters to your liking using the information on this page. Also, it’s important to note that the command is run using “nice”, which will run the conversion process using low priority. That way it shouldn’t affect the overall performance of your system.
4. It sets the label colour of the original file to green, which assuming the next step works will be worthless. It’s just good measure.
5. The original file is deleted so that all you have left over is the MP4 version of the original video.
6. That’s it. If any error occurs during the conversion process or on any of the other steps the label colour of the original file will be set to red. That way you’ll know something didn’t go as expected. Plus if the label colour is set to red the video will not be reprocessed if you decide to run the script again, unless you manually remove the label colour by right-clicking on the file.
Download the script here:handbrake_conversion.zip
Notes about the code:
• You can specify any extensions you want to include in the conversion process, but it really only works with extensions that are 3 characters based on the way it generates the filename of the new path. I’m sure this can be improved, but I only wanted AVI and MKV files converted.
• You’ll likely need to update the folder location that is searched. The way the path is specified is in an AppleScript format, and this may help you if you’ve never dealt with them before.
• This is is assuming you’ve downloaded HandbrakeCLI and put it in the Applications folder.
• You can use this with folder actions if you uncomment the first and last lines. Keep in mind that this enables it to run when a file is added to a particular folder, but will still process every matching file in that folder. It doesn’t actually use the items it is passed.
• You can schedule this to run at certain times using iCal.
There are probably much more elegant ways of doing this, but this works well for me. Hopefully this will at least point some of you in the right direction for customising your own script.







vBulletin Message