AutoHandbrake – DVD ripping wizard

This post is based on a talk a gave at OggCamp 17 in Canterbury last weekend.

At home I run an Emby server to store and stream my music and video libraries, primary to my living room PC which runs Kodi. I’ve got a reasonably large DVD collection which contains an mixture of movies and TV episodes, which I wanted to rip and store on my Emby server. (Note, this post won’t go into the ethics or legality of ripping DVDs, it’s purely a technical discussion).

Currently, the state of the art for ripping and encoding video from a DVD on Linux is Handbrake. Handbrake looks like this:

Screenshot of the Handbrake GUI

The process for ripping a DVD of TV episodes with Handbrake does something like this:

  1. Insert your DVD and let Handbrake scan it.
  2. Select the first title you want to rip.
  3. Select any subtitle tracks you want to include, and specify the subtitle mode (more in this later).
  4. If you want non-default encoding settings, select your encoding preset.
  5. Enter the name for the output file, including any episode numbers.
  6. Add it to the queue.
  7. Repeat all of the above steps for each episode on the DVD.
  8. Run all the jobs in the queue.
  9. Discover you forgot the change the episode number on one of the episodes and overwrote the previous file.

As you can see, doing this for a large number of DVDs is quite labour-intensive, and the Handbrake GUI doesn’t do you a lot of favours. Handbrake also includes a command-line interface which lets you specify all of the settings mentioned above as command-line arguments. However, this requires you know things like tile and subtitle track numbers for what you want to rip.

My solution to this has been to write AutoHandbrake (autohb for short). This is a tool written in Ruby, which uses HandbrakeCLI to find out what’s on a DVD, then present you with a series of questions, and generate HandbrakeCLI commands to rip all the titles you want with the same settings.

The first thing AutoHandbake does is work out what’s on the DVD. To do this, it extracts the list of titles, and performs some analysis of the number and duration. In the case of a movie, you usually have a single long title with the “main feature” flag set. In the case of a set of TV episodes, you usually have between 4 and 8 similar-length titles, along with one “main feature” title that is around the same length as the all the similar-length titles added together (this is the ‘Play All’ option). The script will try and work out which one it’s got, then tell you what it thinks and ask you if it’s correct.

Screeshot of Auto Handbrake, with the text "Single main feature found: Title 1 [41 minutes and 49 seconds]. Rip this feature?", options "Yes" and "No"In this case, the DVD contains a set of TV epsiodes, but the ‘Play All’ title isn’t marked as the main feature, so it’s decided the DVD contains a single feature. This is wrong, so selecting “No” will allow you to correct it.

List of titles. The first 4 titles have the duration 41:49 and are all selected.  The rest of the titles have different durations and are not selected.

Here we get a list of titles to select. The original iteration of AutoHandbrake simply presented command-line prompts, and you typed in the numbers of the titles you wanted. However, I now use a tool called xdialog (via the rdialog ruby gem), which lets you easily display a curses interface for the required prompts when you run from the command line (as I usually do). As an added bonus, if you’re running in a desktop session, you get a proper GUI instead, like this:

The same title list as the previous image, but with an X Windows interface instead of a curses interface.

Once we’ve selected the titles we want to rip, we want to choose which subtitles to use.

AutoHandbrake prompt, question "Add subtitles with default settings? (Language eng, Forced Only: yes, Burned in: yes)", options "Yes", "No".

By default AutoHandbrake will try and autodetect subtitles in the default language. It will also rip use the “forced only” flag, (only include subtiltes where a character is speaking in a different language) and the “burned in” flag (encode the subtitle text directly onto the video, rather than just including the track in the file). It’s fine to accept these options, but for some reason auto-detecting subtitles requires handbrake to scan through the whole title and extra time. Answering “no” here lets us specify the track ourselves.

List of subtitle tracks. 2 options with the text "English", the first is selected.

Sometimes you’ll have options for several languages. Often there are more than one “English” options. I always just choose the first one, and I’ve never had a problem.

Text input, labelled "Enter the title for file and folder naming", the content is "Stargate Sg1"Next we’re asked to enter a title. This will be used to name the destination folder for the ripped files, and the start of the filenames (the whole filename if we’re ripping a movie). The DVD has a “title” field in its metadata which will be used as the default value. Sometimes this is spot on, usually it just needs a bit of fixing, but sometimes it’s complete nonsense. I’ve also had some interesting results here; for example, the first “Star Trek” film in the alternative timeline has the DVD title as “Start Trek XI”.

Text input, labelled "Enter season number for episode naming (Leave blank for none)". Text entered is 10.

If we’re ripping a set of epsiodes rather than a single movie, we’ll be asked for the season number. This will be appended to the file name in the format “S##”, so if we enter a number less than 10 it will have the leading 0 added.

Text input, labelled "Enter first number for episode naming", text entered is "1"

The final input is for the first episode number on the disc. If you have 4 episodes starting with episode 5, entering 5 here will auto-number the episodes 05, 06, 07 and 08. Combined with the title and season number, this gives us file names that looks like “Stargate SG-1 S10E02”.

Prompt displaying a list of HandbrakeCLI commands to rip and encode 4 titles.Now we’ve got our queue of HandbrakeCLI commands. We can check that we’ve selected the right options, and the generated titles are as we expected. Selecting “Yes” here will run the commands and rip the videos!

Terminal window showing the output of the HandbrakeCLI commandThis part of the process could do with some improvement. Currently it drops us to the terminal at this point and we just see the output of HandbrakeCLI. This shows us the time left in the current tasks, but doesn’t really give us an idea of the overall progress. This currently only shows if you’ve run AutoHandbrake from the terminal, otherwise you wont see any output at this point and you just have to wait for it to finish. When its done, the DVD drive will automatically eject the disc.

Usage information for AutoHandbrake, listing the available command line options.There are several options that you can specify a when invoking AutoHandbrake. The input device and output directory are the only ones that are really required. If you know what you want to rip, the rest of the arguments allow you to specify things like the title and season number in the command, in which case it wont ask you for them later.

Another interesting option is “min-duration”. Some publisher will fill the DVD with junk titles of a few seconds long, presumably to make it harder to find what you want to rip. By specifying a minimum duration of a few minutes, you can have Autohandbrake ignore these shorter titles, giving you just the likely candidates to choose from.

You can see, download an contribute to AutoHandbrake on Github.

Bookmark the permalink.

One Response to AutoHandbrake – DVD ripping wizard

  1. Mike Hingley says:

    There’s a robot system that might be interesting – particularly if you have multiple DVD’s of the same type (for example : If I’m ripping my Dr Who Classic series DVD’s then look for episodes of 30 minutes (or whatever they were).

    http://www.britishideas.com/2013/09/03/jack-the-ripper-bot-i-introduction/

    I might have a go with your script though because I really need to sort out our DVD collection, and I’d like to get them streaming on the network – ideally to a chromecast though (as I already have chromecasts on the TV’s).

Leave a Reply

Your email address will not be published. Required fields are marked *