Steve's World Home   Geography Info   Image/Photo Archive   IRC Stats   Software   Linux Tips   Steve's World Info 

Linux DVD Audio Ripping Tips

We sure have come a long way from both portable cassette tape (and then CD) players and the original 2x CD-ROM drives with software players that did cool things like (gasp!) retrieving the artist and disc information from freedb.org... Personally, even with a 4 or 5 disc CD cartridge, I got tired of physically shuffling audio CDs many years ago, and now I really enjoy the convenience of digital audio in its various encodings, along with modern hardware, ie, portable mp3/ogg players, car mp3 audio, and an array of inexpensive peripherals such as 24-bit audio cards and well-designed speaker systems (I pretty much have to make mp3 CDs for the truck, since each disc holds about 10 hours of music, and you can't get much cheaper than blank CD-R discs :) If you're in the market for a little media player, look one that supports ogg vorbis or flac (eg, iRiver, Insignia, etc).

For several years now I've been ripping all my audio CDs before I even listen to them, and the resulting files go onto CDs, as well as a small streaming audio server; a Kurobox running Gentoo Linux that sits in the firewall cabinet and does things like local DNS, automated backups, and streaming audio (using a lovely little python app called Edna written by Greg Stein). But audio CDs aren't the point of this topic, since all these great DVDs starting coming out; I guess it started with several that my wife bought a while back, and I really had to have some audio rips of the bonus disc that came with the Grateful Dead movie DVD...

Tools

There are basically three different tools for ripping and transcoding the content from DVDs (both audio and video) on Linux; they all share many of the same library dependencies for certain functions/capabilities, but they're sufficiently different in their own right that if one doesn't work for some reason (see below for one such case), then one of the others should. There are also several ancillary tools you'll need, some of which you probably already have, such as the lame encoder, the ogg-vorbis tools, flac, etc, and others will make certain things easier, such as vobcopy or dvdbackup. For the full feature set, the required dependencies include several video libraries as well, depending on the formats you need, however, we're not focusing on the video side of transcoding, as that is reasonably well documented elsewhere, such as the transcode wiki or this guide (the latter is a bit dated, but still useful). If you need specific guidance, such as how to transcode a DVD and play it on a little handheld video player, then Google is still your friend...

The following tools are suggested for audio ripping, and at least one of the first three ripping/transcoding tools is required:

Note: the command-line examples are kept mostly for historical reasons (or if the GUI just doesn't do it for you).

GUI example

While the above dvd::rip GUI is very feature-rich in general, the process for ripping DVD audio is fairly straight-forward (if not obvious at first). These steps will produce a .wav file for each chapter on the given title. While .wav files are required for editing, more post-processing is required to generate other formats such as MP3, ogg vorbis, or flac.

Pop in your DVD and launch dvd::rip, then define a project (you really can't do much until you name and save a project; make sure it's in a place with plenty of disk space).

In the Storage Tab:

In the Rip Title Tab:

This will rip the entire title, and all audio tracks, to some .vob files in your project directory specified above. Then, when the ripping is complete... This will rip each chapter, which normally corresponds to a single song/track on a music DVD, to a WAV file under the AVI folder. Delete any non-playable artifact chapters, rename using the song titles, and encode to flac. Then you can use EasyTag (or another tool) to fill in the tags.

Command-line examples

Let's start with a concrete example; suppose you have a concert DVD with some nice music you'd really like to listen to when you can't really watch a DVD (so the ultimate goal is a set of encoded audio files you can play just like the tracks you rip from regular audio CDs). For the most part, we won't get into the merits of lossy vs. lossless encoding, or which bit-rates sound better; if the source material is good quality, for example, pick just about any of the recent Zappa or King Crimson releases, and the standard 128-kbps mp3s made from ripping the audio CDs sound perfectly fine on decent hardware (especially with some road noise thrown in for good measure). In the commands that follow, and throughout this document, things seem to work best with the DVD unmounted. vobcopy is the only command that requires the disc to be mounted (and you must provide the path to the mount point on the commandline).

So pop in your DVD of choice (a recent example might be the Zappa Plays Zappa DVD from last year's tour by Dweezil Zappa and various Mothers of Invention) and we'll follow a basic step-by-step process for scanning, ripping, and encoding one of the available audio tracks into mp3s for convenient listening on your favorite player. The first thing is to inspect the disc; you can do this manually with several tools, or with the dvd::rip GUI. We'll use the transcode commandline tools:

  1. Scan the disc TOC for title, chapter, and audio track numbers using the transcode utilities; note the dvd device can be a real dvd device or the directory where you copied the VOB files:
  2. 
    #~ $ tcprobe -i /dev/dvdrw1
    
    [tcprobe] DVD image/device
    (dvd_reader.c) mpeg2 ntsc 16:9 only letterboxed U0 720x480 video
    (dvd_reader.c) lpcm en 16bit 48kHz 2Ch 
    (dvd_reader.c) ac3 en drc 48kHz 6Ch 
    (dvd_reader.c) subtitle 00= 
    (dvd_reader.c) DVD title 1/2: 16 chapter(s), 1 angle(s), title set 1
    (dvd_reader.c) title playback time: 01:54:21.07  6862 sec
    (dvd_reader.c) [Chapter 01] 00:00:00.000 , block from 0 to 293870
    (dvd_reader.c) [Chapter 02] 00:09:04.367 , block from 293871 to 532255
       ...[snip]...
    (dvd_reader.c) [Chapter 15] 01:43:07.832 , block from 3340117 to 3703349
    (dvd_reader.c) [Chapter 16] 01:54:20.832 , block from 3703350 to 3703357
    [tcprobe] summary for /dev/dvdrw1, (*) = not default, 0 = not detected
    import frame size: -g 720x480 [720x576] (*)
         aspect ratio: 16:9 (*)
           frame rate: -f 23.976 [25.000] frc=1 (*)
          audio track: -a 0 [0] -e 48000,16,2 [48000,16,2] -n 0x10001 [0x2000] (*)
          audio track: -a 1 [0] -e 48000,16,2 [48000,16,2] -n 0x2000 [0x2000] 
    [tcprobe] V: 164524 frames, 6862 sec @ 23.976 fps
    [tcprobe] A: 107.22 MB @ 128 kbps
       ...[snip]...
    

    Note: the important info above is 1) which title has all the chapters and how many, and 2) which audio tracks are which format. Typical music DVDs seem to have at least one LPCM stereo track and one AC3 surround track, and you'll generally want the PCM stereo track (although transcode will automatically convert the surround track if you want). You just have to specify which title, chapter(s), and audio track you want.

  3. Scan the desired audio track for the recommended scale parameter; if you go above this value you run the risk of clipping the signal, but if you don't scale at all it might not sound very loud compared to other mp3s:
  4. 
    #~ $ tccat -T 1,1,1 -i /dev/dvdrw1 -t dvd -a 0 -L -d 2 | tcextract -t vob -x pcm | tcscan -x pcm -d 1
    
    The above command grabs the first title,chapter,angle with the -T parameter, from the dvd drive (with the -i parameter, which could also be a directory with VOB files). The -a parameter asks for track 0 (the linear PCM stereo track) while the -L parameter loops through all the chapters, and -d increases the verbosity of the output. This gets piped to the tcextract command which looks for a pcm stream (note this parameter would be ac3 for the surround track 1). This in turn gets piped to tcscan, which scans the pcm data and will spit out the proper normalize value for the given audio track (or the whole disc). Without looping through all the chapters, the output from scanning just the first chapter looks like this:
    
    # ~ $ tccat -T 1,1,1 -i /dev/dvdrw1 -t dvd -a 0 -d 2 | tcextract -t vob -x pcm | tcscan -x pcm -d 1
    T=3 1 1 1 1
    (dvd_reader.c) DVD title 1: 16 chapter(s), 1 angle(s)
    (dvd_reader.c) DVD playback time: 01:54:21.07
    [tccat] (pid=12865) processing chapter (1/16)
    (iodump.c) PAL DVD image/device
    [tcscan] audio frames=13620.67, estimated clip length=544.83 seconds
    [tcscan] (min/max) amplitude=(-0.996/0.996), suggested volume rescale=1.004
    [tcscan] V: 13620 frames, 544 sec @ 25.000 fps
    [tcscan] A: 8.50 MB @ 128 kbps
    [tcscan] CD:  650 MB | V:  641.5 MB @ 9892.1 kbps
    [tcscan] CD:  700 MB | V:  691.5 MB @ 10663.1 kbps
    [tcscan] CD: 1300 MB | V: 1291.5 MB @ 19915.2 kbps
    [tcscan] CD: 1400 MB | V: 1391.5 MB @ 21457.3 kbps
    

    The rescale value in this case may seem rather low at only 1.004, but each disc is different, so it's worth doing this step in the vast majority of cases. Make sure to scan all the chapters, and we'll use the suggested volume rescale value in the actual transcode command below.

  5. Now we can actually do the ripping, transcoding, and audio encoding all in one command, at least for mp3 output:
  6. 
    #~ $ transcode -i /dev/dvdrw1 -x null,auto --no_split -T 1,-1 -s 1.004 -a 0 -y null,raw -m zappa_plays_zappa.mp3
    

    Note the above command will produce a single mp3 file of the first audio track from Title 1 (the entire disc). Although transcode has a chapter switch, this method only seems to handle ripping to *.avi files from which you would have to extract the mp3 audio tracks. The easiest method I found was to code the above command in a shell script, which we can call with several arguments to specify the title, audio track, scaling parameter, etc. This produces a separate mp3 file for each chapter on the disc, which in the case of all the music DVDs I've tried so far, corresponds to a single song per chapter. The only drawback of this method is the manual post-processing involved, mainly renaming the mp3 files for each song title and adding tags. If you don't like mp3s, then you can always dump the PCM data and then encode with your favorite encoder such as ogg or flac (feel free to enhance the script for other encoding formats :)

    You can also rip audio from digital movie files. To extract the audio track from en existing .avi file, which in this case is in AC3 surround format, you can use the following command to dump the audio as an uncompressed PCM stereo track. From there you can encode as flac, ogg, or whatever. The -N switch is what specifies stereo output, and -s just adds a little bit of volume boost (optional).

    
    #~ $ transcode -i temp.avi -x null,auto -s 1.008 -a 0 -y null,raw -N 0x1 -m audio_track.wav
    

    Other things to note in the above command are the -x and -y parameters; null is for not processing any video (which seems to speed things up a bit) and using -T 1,-1 grabs all the chapters from title 1. Also, the above command is really just a frontend for the previous tools, which you'll see in the output (ie, which commands/parameters are actually called and piped together).

  7. As mentioned, a much more convenient form of step 3) above would be to use something like this bash wrapper script to rip each chapter (ie, each song) to a separate file:
    
    #~ $ ~/bin/dvd_audio_rip.sh /dev/dvdrw1 1 16 0 1.004
    
    where the parameters are the ones already discussed, as shown in the script comments below:
    
    #!/usr/bin/env bash
    #
    # usage: ./dvd_audio_rip.sh "device|directory" "title" "num chapters" "audio track" "scale factor"
    #
    # Note: the last chapter is usually not a valid track; delete if zero length.
    #
    # Probe with:
    #   tcprobe -i "device|directory"
    #  - or -
    #   mplayer dvd://title -dvd-device "device|directory" -frames 0 -identify
    #
    # Scan for volume scale factor:
    #   tccat -T 1,-1 -i "device|directory" -t dvd -a 0 -d 2 | tcextract -t vob -x pcm | tcscan -x pcm -d 1
    #
    # for ac3 only, change the tcextract to ac3 and add | tcdecode -x ac3 before tcscan
    
    cha=1
    until [ $cha -gt $3 ]
    do
       transcode -i $1 -x null,auto -s $5 -a $4 -y null,raw -T $2,$cha,1 -m cha-$cha.mp3
       #mplayer dvd://$2 -dvd-device $1 -aid $4 -vc null -vo null -ao pcm:file='cha-$cha.wav' -chapter '$cha-$cha'
       # 
       cha=$(( $cha + 1 ))
    done
    

Notes

Examples are also given in the comments of the above script for using mplayer to probe and rip the same content; as noted above, mplayer doesn't encode to mp3 like transcode does, nor does it re-scale the output. Also, the audio track IDs are different when using mplayer, which are displayed in the output of the mplayer -identify command shown above. Note that transcode works equally well with movie files as input, for example, you could use it to transcode just the audio track inside an AVI/ASF file from ac3 to mp3 (since all the cheap/little mp4 players I've tried so far can play mp3 audio, but not ac3). It's just a matter of setting the -i, -x, and, -y parameters to what you want (which is documented in places such as the above transcode wiki). Note also that transcoding audio is much faster than transcoding video (or both). You really need a pretty fast machine with lots of RAM and disk space for video :)

One reason you might need to use mplayer (or perhaps VLC) is for a DVD-A (or DVD Audio) disc. I only have one example so far (a posthumous Frank Zappa release of the Halloween concerts from 1983) and it has two 24-bit audio tracks (not so) similar to a normal DVD (ie, one PCM stereo track and one DTS surround track). In this case, transcode could not seem to rip either track successfully, either with or without byte-swapping the audio, although I could play the disc just fine with both gxine and mplayer (I didn't try VLC, as I didn't have it installed at the time). So my only option was to use the mplayer method shown in the comments above. The results in this case don't sound quite as good as the transcode method used for most of my DVDs, since I didn't bother to scale the output during the encoding step (which involves some trial-and-error without output from step 2 above). The trial-and-error should also involve listening to the results of ripping both the pcm and ac3 tracks, since one will sound better than the other, depending on the disc.

One last note: if any of the above tools/commands seems to hang while trying to scan more than the disc TOC, then it might be having trouble with the CSS key of the disc. Some discs seem to take a long time to decode, and this seems to reveal some memory leaks and/or other issues with some of the tools (they may be difficult to kill in some cases, and may eat your desktop memory in others). This happened to me with a couple of discs, and the best workaround seems to be using vobcopy to copy the disc to a large temp directory on your hard disk (this will also decrypt the content). Vobcopy will most likely cough an error to the console about the CSS key, and may look like it's not doing anything for a while. Be patient; depending on the disc and how much horsepower you have, it should complete successfully after some period of time. From that point replace the /dev/dvd parameters above with the path to the VOB files, e.g., /tmp/vobs/DISC_NAME (where you told vobcopy to copy the files) and continue as above.

That's about it, since ripping DVDs is currently a bit more complicated than popping in an audio CD and having grip automatically rip, encode, and tag all the tracks for you, you'll need to try some of the above commands manually first and check the results, then probably try again (it takes significantly more time just to scan and rip the content of DVDs because of the large volume of data). That said, it could be done easily in another tab in the dvd::rip GUI, except I'm not sure how it could grab the real chapter titles, unless they're accessible from IMDB, like CDDB is for audio discs...


 Steve's World Home   Geography Info   Image/Photo Archive   IRC Stats   Software   Linux Tips   Steve's World Info 

Powered by Zope