Wednesday 29 July 2009

EyeTV Export with HandBrake script

EyeTV by Elgato is an excellent piece of software that turns a Mac into a Personal Video Recorder. You can record programs using a tuner and play them back at any time. We have an iMac stuck to the wall in our living room that acts as our TV and media player. Even the babysitter can use the PVR interface and we get to use full apps like iPhoto and Spotify on our TV.

EyeTV records video using the format that it’s sent over the air. This is currently MPEG-2 for Freeview programs, which is decent quality but reasonably large files. I’d like to be able to archive my recordings using a better encoding such as H.264. However, EyeTV’s (and Apple’s) built-in options for exporting video are pretty poor. They generally take a long time to create poor quality video at an unimpressive compression ratio.

HandBrake is an open-source video transcoder. It can transcode between many video formats and has built-in presets for compressing different kinds of video. It’s great at taking EyeTV recordings and transcoding them into space-efficient, high quality H.264 MKV or MP4 files.

Fitting the two together is a bit of a pain. EyeTV has Applescript support but HandBrake doesn’t. Instead HandBrake has a command-line version that is available for separate download (see the downloads for Command Line Interface).

I wanted to be able to choose a suitable HandBrake export preset (some of my recordings are cartoons, some are movies) and a destination folder and export several recordings at once. Since transcoding video is a CPU hog, I also wanted to use the HandBrake encoding queue, but this isn’t available in the command-line version.

Various people have written scripts to take EyeTV recordings and encode them using HandBrake, but they weren’t quite what I wanted. Most of them were intended to import the results into iTunes so that files are available to AppleTV. I did’t need this — I just want smaller files. And none of them had an encoding queue — they all ran in the foreground.

So I wrestled with Applescript (it felt like banging my head against a brick wall several times), honed my shell script skills and built the EyeTV Export with HandBrake script. The script can be added to the EyeTV scripts menu, so that you can select multiple recordings in EyeTV and export them directly. The script will prompt you for a HandBrake encoding preset and an output directory and will pass of the encodes to a background shell script that runs one encode at a time. If you have Growl (also highly recommended), the script will announce completed encoding processes in a friendly manner (otherwise it will pop up a dialog).

I hope you find it useful. Please add comments below!

Instructions

  1. Download the script (or get the source from GitHub)
  2. Put it in /Library/Application Support/EyeTV/Scripts and restart EyeTV (see EyeTV Applescript instructions for details)
  3. Download the HandBrake Command Line Interface (HandBrakeCLI) and move it somewhere appropriate. I use /usr/local/bin/, but the script will ask you to find it if it’s not there
  4. Select one or more recordings and choose “Export with HandBrake” from the Scripts menu (just between Window and Help)

23 comments:

Unknown said...

Adam almost exactly what i have been looking for, is it possible to get this script to export the mpeg2 stream and rename it as the containing folder. Sorry for asking but im and apple script Noob and i can figure out how to do this

David said...

Adam,
Thank you for your excellent script.
I was in the midst of trying to convert the many EyeTv programs that I had accumulated to mp4s using Handbrake and was finding it very tedious with many Handbrake crashes - I think mainly due to the GUI.
I was investigating the use of the CLI when I chanced upon your script and all is going well so far.
Some observations -
I think that writing to the logfile every second is too frequent. Every 10 or 15 seconds would be fine and produce far smaller log files.
The queueing techniques breaks down when there are many members. I queued 15 item and 5 of them kicked off simultaneously. It would have taken 42 hours for them all to complete :-). Not really a dealbreaker, I suppose, but I would rather do one at a time.
I am not a software expert, but will download your source from Github and have a look - I hope I can learn something. I will let you know if I have any suggestions.

David said...

Adam,
I had a look at your script and increased two of the delays.
The first to 5, which seemed to solve the problem of multiple runs starting simultaneously. I started 15 and they all queued properly.
The second to 30, which reduces the number of entries in the message logs from the members of the queue while they are waiting to start.

echo "`date`: starting $0"
sleep 5 # to let other handbrake encoders start
while [ `other_encodes_are_still_running` -gt 0 ]; do
sleep 30
echo "`date`: waiting for other encodes to finish"
done

Adam Cohen-Rose said...

Thanks David!

I've added those changes into the github master.

dubjbl said...

Thank you for sharing your excellent script and providing such a clear explanation of how to use it. I am wondering if you have experimented at all with using this as a Triggered Script in EyeTV? I'd like it to trigger when EyeTV is done recording a show, and export/transcode the show to a network drive. Some aspects of your script would need to be modified to eliminate the user entry points, and export settings would need to be predefined. I'm brand new to AppleScript, so not sure how to do this myself yet, but thick into research...

Rene said...

Thanks for the nice script. Unfortunately, I can't get it to work properly. Either I have no audio stream exported if I select normal, or classic and any Quicktime exports only create a 20 kB file. Is there a log I can look up what's wrong.I have the Handbrake CLI in a different directory than your default but the script is bale to locate it. Any ideas?

Tonty said...

Fantatic script. I'd like modify it slightly, but can't figure out how to compile it. Some instructions would be really helpful.

Anonymous said...

Hello,

I found your blog entry on EyeTv export via an AppleScript and Handbrake CLI. I installed them and it works just fine, but you were mentioning on another website a PS3 preset ... I can't see it in the export format list ! Did I miss something ?
Best regards.
P.J.

Anonymous said...

Hi,

as a reader before asked, is it possible to have this triggered automaticall after every recording with a predefined set ?
I just want all recordings to be exported to a network share so I can view those with xbmc and plex from any other machine.

Adam Cohen-Rose said...

I've actually stopped using this script since the latest release of Handbrake -- now you can just drag an EyeTV recording into the Handbrake source dialog and it will work with all the GUI niceness (including a proper queue).

For those that want to alter the script to be a triggered script, you may want to explore EyeTV's iPhone Access options (though the encoding won't be using Handbrake...). Alternatively, please feel free to fork the code on GitHub and play around!

Galoomp said...

I've been looking for something like this for a while now. Will give this a try this evening. Cheers!

Unknown said...
This comment has been removed by the author.
Unknown said...

Thank you for creating! I use this script because the scheduled exporting through EyeTV does not allow me to specify the export location, for example I would like to save all my exported movies to the external HD and not the iTunes Music folder.

Anonymous said...

I just started fooling around with your script, which looks like it should do the trick, but I see you said as of the latest release you don't need to use the CLI. I have a Mac, and I've tried dragging it to the source dialog, and it's not doing what I hoped it would. I'm assuming you're talking about the windows version?

Anyway, thanks for the hard work!

Adam Cohen-Rose said...

@Anonymous no, it works fine in the Mac version of HandBrake. Just drag the programme from the EyeTV window to the open file sheet that appears when you click on the Source button in HandBrake.

All this does is help you locate the .eyetv file for the programme -- and HandBrake can figure out how to deal with the file.

I'm using the latest version of HandBrake -- v.0.9.4

Redfive said...

Can this export to MKV? I think it chose the default file format of the preset (High Profile) which is MP4. If I run the HandBrakeCLI and list the presets, it says it's using the x264.

Anonymous said...

Awesome work, can I have the option to make it a mkv rather than a mp4 file ?

Anonymous said...

Hi Adam. Thank you for your script. Its greast with the queue and the growl notifications. I was thinking if you would spend 5 minutes writing how I can add my own Handbrake parameters in your script in stead of the presets. I usually don't use presets, as I like to have the second audiotrack being DolbyDigital (AC3) 5.1.

Unknown said...

Hi there, I have just downloaded your file and looked on the github site, but there doesn't appear to be any script there. ? There's an app and two text files but no script. Am I missing something? If you could help I would be very grateful as this is just whatI am looking for. Thank you. Lynden

David said...

Lynden,

The script is embedded in the app.
Right click on it and select Show Package Contents. Then drill down to Resources - there you will find scripts.

David said...

However, the real answer to you implied question is - place the app in the location described by Adam (the app is an encapsulated script).
In more recent versions of OS X you may need to launch the app first so that you get gatekeeper to authenticate it. Right mouse click, open, then click open in the dialogue box.

Unknown said...

Thank you for your help - all sorted now!

gb160 said...

Great script...i have just one issue,my custom handbrake presets dont appear in the list of presets.
is this possible?
Any help is greatly appreciated.