DVD ripping with Linux/*BSD/OS X



Hi, this short tutorial aims to be a guide for those who would like to back up a DVD using Linux. If you like nice and clear GUIs I suggest you to use the excellent Handbrake, but if you are interested in understanding what really happens when ripping a DVD and have complete control over the operation you will find this guide quite useful.

At first I will start with a general overview to clarify the situation about DVDs, then I'll switch to a description of the script I made, along with its usage. Remember that this does not pretend to be an exhaustive study about DVD encoding, it is a simple introduction to this beautiful World, for further information I suggest you to follow these links:

  • DVD ripping and transcoding with Linux. This is a very specific tutorial about the DVD ripping and transcoding, using MPlayer and Transcode. It is well organized and it contains specific information about the codecs, the aspect ratio, the audio and other specifics. Recommended.
  • Mplayer HOWTO. The original MPlayer HOWTO. They are a huge and precious source of information of any kind about the video playing/encoding. Plus, the supported OS are Linux, Windows, Mac OS X, FreeBSD... you got it. A must for any serious user, everybody should take a careful look at it.

Some information about the codecs.

In this section I will explain the choice of the video codecs I used to make the script, and the reason upon which I made this decision.

Codecs and Containers

  • Video codec My choice is MPEG4, which in MPlayer is the ISO standard MPEG-4 (DivX 5, XVID compatible).You can also use x264 of ff264, open implementations of Apple's h264. Although I think the title explains itself, I will spend a few words about it. It is crucial to have an open standard, so that anybody, anywhere, will be able to play the video, no matter the OS used (*UNIX, Linux, Windows, Mac OS X) or the architecture upon which the OS is working (x86, SPARC, PPC, ALPHA), therefore we should use the so called "open standards".

    For further information about this topic, I redirect you to these links:
    :: Linux Open Standards
    :: Wikipedia Definition

  • Audio codec Vorbis, using the OGG container. Same reason as above, plus some extra special motivations. OGG Vorbis is a completely open, patent-free, professional audio encoding and streaming technology with all the benefits of Open Source. Listening tests [1] (http://www.rjamorim.com/test/) have attempted to find the best quality lossy audio codecs at certain bitrates. The tests show that: at 128 kbit/s, Ogg Vorbis and MPC performed marginally better than other codecs. Based on this, Vorbis can be considered a high quality codec. For most applications Vorbis is a good codec to use, but would only be considered superior to other modern codecs because it is patent free.

    For further information about this topic, I redirect you to these links:
    :: Vorbis Official page
    :: Wikipedia Definition

  • Container The Choice was between OGM (Ogg Media) and MKV (Matroska). Without any doubt, I would not have chosen avi, which is probably the worst container for audio and video that ever existed in this planet. I will quote the official matroska home page to make you understand what it is capable of:

    Matroska aims to become THE standard of multimedia container formats. It was derived from a project called MCF, but differentiates from it significantly because it is based on EBML (Extensible Binary Meta Language), a binary derivative of XML. EBML enables the Matroska Development Team to gain significant advantages in terms of future format extensibility, without breaking file support in old parsers.

    First, it is essential to clarify exactly "What an Audio/Video container is", in order to avoid any misunderstandings. Matroska:

    • It is NOT a video or audio compression format (video codec)
    • It is an envelope for which there can be many audio, video and subtitles streams, allowing the user to store a complete movie or CD in a single file.

    Matroska is designed with the future in mind. It incorporates features you would expect from a modern container format, like:

    • Fast seeking in the file
    • High error recovery
    • Chapter entries
    • Selectable subtitle streams
    • Selectable audio streams
    • Modularly Extendable
    • Streamable over internet (HTTP and RTP audio & video streams)
    • Menus (like DVDs have)

    Matroska is an open standards project. This means for personal use it is absolutely free to use and that the technical specifications describing the bitstream are open to everybody, even to companies that would like to support it in their products. The source code of the libraries developed by the Matroska Development Team is licensed under GNU L-GPL.

    In the end I just found Matroska more performing than OGM, which has similar functionalities. For further information about this topic, I redirect you to these links:
    :: Official matroska Home Page
    :: Wikipedia Definition

Let's get started: Encoding!

Now that we have a general overview of what is the difference between a video codec and a container, we are acknowledged about the codecs that we are going to use and the reason of this choice, we can start with the very essence of this tutorial, the encoding.

My decision to use the omnipotent MPlayer and MEncoder was very easy. At first, it is an open standard. Secondly, it works really fast, it has an enormous number of parameters for the playing/encoding of almost any media that exists; and thirdly it has a very big and open community willing to help those who are in need, plus the documentation is exahustive and clear. Some info about the Mplayer project can be found here:
:: Mplayer Home Page.

Let us now make the situation clear. We are about to do the following tasks in chronological order:

  1. Ripping the audio
  2. Ripping the video - First pass
  3. Ripping the video - Second pass
  4. Merge the audio and the video into a single MKV file

Audio encoding

It looks pretty simple, though. The first operation can be done in two different ways. The first one if to create a FIFOTEMP, this will make the whole process a bit longer, but you won't need to have +1GB space just for an audio that you would have to dump anyways. Furthermore, the audio encoding through a FIFOTEMP works pretty fast in my PowerBook G4 1.33GHz, so I think it won't be a problem for a modern computer (which is really required for good DVD ripping). The commands that you'll have to use are the following:

 mknod fifotemp p&
 oggenc -Q -q 3 -o audio.ogg fifotemp 
 mplayer -dvd-device $DEVICE dvd://$TITLE -aid 128 -vc dummy \
 -vo null -hardframedrop -ao pcm:fast:file=fifotemp&
 rm fifotemp&

These commands will create a FIFOTEMP (First-In-First-Out Temporary), encode in vorbis the audio that mplayer will produce dumping the video; finally remove the FIFOTEMP when all it's done. The second way to achieve the same result will be this:

 mplayer -dvd-device $1 dvd://$2 -aid 128 -vc null -vo null\
 -hardframedrop -ao pcm:file=audio.wav&
 oggenc -q 3 -o audio.ogg audio.wav&

This will eventually takes even longer, since it has to encode all the audio before, and then run the oggenc. The single operation will be faster than the FIFOTEMP, also the computer will no be overloaded; but the overall result may not as good as you wanted to. In the script I put as default the FIFOTEMP, and I commented with # the other solution, just switch and uncomment if you wish to use the other one.

Video Encoding

At this point we should have an audio file called audio.ogg that contains all the DVD audio track in a 128kBit/sec vorbis. The encoding will be done using mencoder, but first we should specify the option we wish to use.


This local variable OPT contains the options for the 2-pass encoding process. For specifics about all the options used about luminosity, FPS, scaling, etc... see the Mencoder manual.

it is now time to pass to the real encoding process, use the following commands:

 mencoder -dvd-device $DEVICE dvd://$TITLE -aid 128 -vf \
 crop=$CROP -ovc lavc -lavcopts $OPT:vpass=1:turbo \
 -nosound -o /dev/null & 
 mencoder -dvd-device $DEVICE dvd://$TITLE -aid 128 -vf \
 crop=$CROP -ovc lavc -lavcopts $OPT:vpass=2 -nosound \
 -o output.avi & 

The result will be saved in a file named output.avi, containing the original AC3 audio, and the video, encoded with the bitrate previously specified.

Merging the video, create the MKV

A very simple command is needed:

 mkvmerge --title $NAME -o $NAME.mkv -A output.avi \
 --language 0:eng audio.ogg

The vorbis audio will be merged together with the video, the old AC3 will be replaced, and as a result we'll have the MKV desired.

I assembled all these command into a bash script that will do the job for you. The tar.bz2 contains three file:

  • ripdvd - Does all the job, see below.

It is quite simple, I will report the README file as it follows:

 - dvd-device = your dvd-device. Either a on-the-fly copy 
 (/dev/dvd) or a local directory, created before with vobcopy
 - dvd title = the title of the dvd using mencoder (e.g mencoder 
 dvd://1, also multiple titles, like 2-6 = from 2 to 6)
 - bitrate = the bitrate to use for the ffmpeg compression 
 (DivX, Xvid) (best > 900, 1100 is fair enough.)
 - crop = That if you wish to crop the black bars.
 - If no argument is provided the script will perform a standard 
 rip in /dev/dvd at 1100Kb/sec, English language with output 
 file named dvdout.mkv
Common options:
 -h, --help - display this help text
 -dep	 - only install dependencies (requires sudo/root)
 -crop - crop detect
 -c - custom, start a step-by-step guided rip [EASIER]

 [bash]$: ripdvd
 [bash]$: ripdvd -c

 -rw------- 1 phate phate 700M May 5 04:09 dvdout.mkv
 -rw------- 1 phate phate 700M May 5 06:12 Avalon.mkv

SourceForge :: Project Home page.

FreshMeat :: Project Home page.

In order to install the script see the README, or open a terminal and copy paste the following code, line by line:

 unzip dvdriptools-0.6.1.zip
 cd dvdriptools && sudo ./installit

Enjoy the script.

For further information, suggestions, bug fix, send me an email.