Saturday, 25 February 2017

Ripping DVDs on Ubuntu 16.10

A recent reconfiguration of our living room caused a problem. The HDMI cable from the DVD player was not long enough to reach the television in its new position. We couldn't watch DVDs any more! "Get a new cable", you might say. Hah! No, as a man au fait and indeed au courant with technology, I knew what the answer was. It was time to rip all our DVDs and host them on a DLNA server.

I've actually attempted this before, but found it hard work, and I was never particularly satisfied with the results. Still, faced with the alternative of having to buy an entire cable - and possibly spend as much as £5 - it was time to try again.

Required software

There are a quite a lot of tools around but sticking with the free, and after a little experimentation, this is what I have ended up using:
  • VLC: everyone's favourite media player. If you haven't already got this installed, why not? VLC can play just about anything and is useful for checking which DVD title to extract (more on this later) and verifying the rip afterwards: sudo apt-get install vlc
  • Handbrake: the open source ripper of choice. Much improved since last time I tried it. Unfortunately the version in the standard Ubuntu repos is ancient, so we'll have to use a PPA.
  • libdvdcss2: the DVD decryption, needed because of the largely pointless industry practice of "encrypting" DVDs to prevent piracy. Because of the lack of clarity around whether ripping DVDs for private use is allowed, this isn't officially distributed by Ubuntu. But they do distribute a package that will install it for you, if you tell it to. So that's OK then. (standard disclaimer: consult a lawyer in your jurisdiction yadda yadda yadda. Yeah right)
  • ddrescue: a "data recovery tool", used for a couple of reasons: firstly, to allow us to queue up multiple DVDs to rip without having to sit up all night swapping disks in and out; and secondly to get round the more egregious copy protection on most Disney DVDs.
It's simple to install it all:
sudo add-apt-repository ppa:stebbins/handbrake-releases
sudo apt-get update
sudo apt-get install vlc handbrake-gtk libdvd-pkg gddrescue
sudo dpkg-reconfigure libdvd-pkg

The process

The simplest approach is to insert a disc, let Handbrake scan it (using the CSS decryption automatically), select a title to rip, and let it run. This has a couple of disadvantages though: it's slow, and while it's running you can't do anything else with the DVD drive. So you wait a couple of hours and then swap the disk, then do it all again. Clearly, this will take a while. There's another problem: Handbrake barfs on DVDs that have more advanced copy protection - primarily more recent Disney titles - because the DVDs have deliberately broken sectors and misreported file tables. (This also means older DVD players mess up on these discs. Thanks a bunch, Disney.)

Handbrake allows us to queue up multiple titles to rip, so what we'd like to be able to do is make an image of the disk, missing out the stupid broken sectors, onto the hard disk, and then rip from that image. That's where ddrescue comes in. It can make an ISO of the DVD and deal with (or skip) those sectors. Then once it's on the hard disk, we can get Handbrake to scan the ISO and queue up the title, or titles on that DVD. While Handbrake starts ripping that, we can put another DVD in and make an ISO from that. In this way, we can set up a queue of titles that can run overnight, or while out.

So, first step: copy the DVD to hard disk:
DISK_NAME=film-title; ddrescue -b 2048 -r 3 -Afnv /dev/dvd $DISK_NAME.iso $DISK_NAME.map
One of the things that ddrescue can do is do repeated passes over a disk, and those passes can even be on separate invocations. That's why there's a map file used as well. If the copy works well, the map file won't be needed, but if it gets interrupted for some reason, or the disk is having problems, then the map file will reduce the time needed for the next passes.

Next, play the ISO in VLC. By doing this, we can work out exactly which title to rip. Handbrake does a decent job of working out the right one, but on some it doesn't (particularly those irritating Disney DVDs, which report 99 titles, mostly fake). Also, if you want to rip some additional material, like extras, then you can work your way through the menus to find them too. When the title to rip is playing in VLC, choose the "Playback > Title" menu and it will show which title number is playing.

Now open Handbrake. Choose "Open Source" and select the ISO file you created. It will scan the disk image, create previews for the titles it finds and select the title that is most likely to be the correct one. Usually it chooses correctly, but if not, select it from the drop down. You can then change the various video, audio and subtitle settings. I usually first choose the preset "Super HQ 1080p30 Surround", then go to the "Video" tab and choose "Film" or "Animation". Adjust the audio and subtitle settings to taste. Then start encoding.

Some DVDs are a little more complex. I've found a few that will work only direct from the disc itself, and I have failed outright with a few: so far, "Monsters University", "Shaun The Sheep The Movie" and "Minority Report" (although I have a feeling this latter one is a damaged disk, even though I can't see any damage).

No comments:

Post a Comment