Thursday, September 6, 2012

Automating Video Conversions with Handbrake for AppleTV

The Background Story

I've got a second generation AppleTV.  Not the 1080p, but the one that does 720p.  I have to say that out of all the electronics I own, it probably gets the most use at the most reasonable price.  This thing gets turned on daily and if it weren't for NFL it would probably allow me to cancel my cable account.

In case you are living under a rock and are unfamiliar with the thing here is a link to the apple store that provides a little bit more information. Essentially, you get a nice little box, capable of 1080p for $109.  You keep all the video files on your computer and stream them whenever necessary.  


The one downfall with the AppleTV, as I learned quickly is that its very limiting in the video formats that it is capable of playing.  Other than .mp4, there's really not much you can play.  Luckily, the majority of TV shows that are ripped these days do meet that criteria, however there is still a lot of video out there that does not meet this criteria.  

Fortunately, there's a really nice program out there called Handbrake that is capable of converting almost any file into an .mp4 we can use on the appleTV.  If you have not heard of this program yet, go out and get it NOW.  It's free and does an amazing job of converting all my files over.  


While I was satisfied with running Handbrake at first, I got REALLY tired of always having to load it up, select my files and settings and go ahead with the conversion.  I'm a really lazy person and am always looking for the simplest way to do the job.  That is when I got the great idea of automating the process. If you are running a mac, your computer comes with a great piece of software called Automator.  It's one of those things I never gave a second look to until I realized the power of the program, now I'm using it for almost anything.  

Automator gives you the ability to automate almost any task, and in this case, I got it to automate all conversions from any video format to .mp4.  Once its does the conversion it then moves it automatically into my iTunes and makes it available for me to stream to the appleTV.  I've gone from having to do several steps on my own, to sitting back and letting the computer do the work for me.  Let me explain how I set up the whole process.

Automating my Video Conversions 

The first step to automating video conversion was to download the command-line version of Handbrake.  By downloading the command-line version, we can run a script that will select all the options for us.  Here is the link to the page for downloading the command-line version.


Download the file and place it wherever you want, I put it into the applications directory under my home.  Now lets work on automating the conversion.

Open up automator from your applications and select folder action.  This will create a script that can be run whenever a file is saved to a folder (in this case it will be our video file that triggers the script)

You will see a huge number of options regarding all the tasks that you can automate.  After this blog, you will probably come up with a pile of ideas on your own and thats great, but for now lets stick to the task at hand.  Set up the following tasks as shown in the diagram below.  You might need to make minor adjustments such as changing the directory.  If you are unable to see the text in the pictures below, go to the originals and it should be clear.  You will notice, I use a temp directory that is off the home be sure to create it or the converted file will have no where to go!!!  I use that temp directory to store the converted file before I import it into iTunes. 


Feel free to add the following after if you would like to delete the file from the temp directory after the import.


Once you have the automator script finished all you need to do is set it up so that the script is activated in the right directory.  Save the automator file you just created and go to finder.

In your finder window, right click on the directory that houses all of your video downloads.  Select Folder Actions Setup as shown below.  Once in there you should be able to select the script and make sure it is attached to the automator script you created. 



That's it!  You're now complete and all video download with a file extension of .mkv or .avi should automatically be converted to .mp4 and imported into iTunes.

Hope it works out for you, please leave comments if you have any questions or improvements and let me know how its working out for you.  

9 comments:

  1. Is there any way to get this to keep the original file name? It keeps renaming my files to TV. I'd like to keep the original file, so that I know which file is which.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Is there anyway you could post the full code or at least the snippets of code you used so we're not copying it all off of a photo which leaves so much room for errors?

    ReplyDelete
  4. Video Converter for Mac-Total Video Converter for Mac is your best video converter for Mac to convert all videos to iPad, iPhone... Best all-in-one Video Converter for Mac.

    ReplyDelete
  5. How would I use this and use a preset that i have set up in the handbrake gui?

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Handbrake CLI appears to continue running or atleast Terminal does. Is is there a clean way to kill those processes? Also is there a way to force the next action to wait until the Handbrake CLI job has finished?

    ReplyDelete
  8. Hey, I just visited your blog and it looks like you had done quite good work,thanks for sharing this important Tips About Cloud/Drop Box Video Upload
    Color Label DVD Printing
    Event Recording

    ReplyDelete