Making Audiobooks from DVDs

02 Jul 2006

My fiancee has trouble sleeping and she often benefits from some sort of background noise. We’ve lately been into watching Star Trek - The Next Generation (hey, stop laughing) and she’s found it very easy to sleep to the episodes that are heavy on dialogue. Apparently techno-babble and flux-capacitors are better than any sleep meds.

So I’ve decided to make her a present of DVD TV episodes as audiobooks. She really just wants them for going to sleep so she doesn’t need the video and she’d like to be able to play it on more devices than just something that can play DVDs.

I run Linux exclusively so I needed to find a way to do this using the GNU tools that I could find on my Gentoo installation. I was a little shocked to see that it only took a couple of steps to turn a tv episode into an audiobook.

Finding the episode(s) you want

I like to turn a whole DVD into audiobooks at once, but you might just be looking for a particular episode or track. To find out which track you want, just try the following:

tccat -i /dev/dvd -T {track number you want},-1 | mplayer -

If, say, you wanted to see what the first track was you could just type:

tccat -i /dev/dvd -T 1,-1 | mplayer -

and the first track would be pulled off the DVD and fed into mplayer for you to watch. If you want a different track, just try a different number.

Ripping the episodes to disk

This is fairly straightforward, the first half is the same as above but instead of piping the video into mplayer to watch, we’re saving it on the hard drive.

tccat -i /dev/dvd -T 1,-1 > track_1.vob

Extracting the audio from the dvd file

Mplayer has the built-in capability to extract just the audio from a DVD-type MPEG-2 file and export it as a pcm wave file (the most universally readable type of audio file).

mplayer -vo null -alang en -aid 128 -ao pcm:file=2.wav track_2.vob

The above will create 2.wav from the audio it finds in track_2.vob

Encoding the audio to mp3

This part is wonderfully easy. Make sure you have the lame mp3 encoder installed on your machine. If you don’t have this, you can find any number of other encoders and change your command accordingly.

lame 2.wav 2.mp3

Ripping a whole DVD automatically

This is the fun part. Once I realized I wanted to go through the Star Trek disks one by one and turn each episode into an audiobook I knew I didn’t want to have to type the above commands more than once so I threw it into a batch script.

This can take a single number as an argument and it’ll process just that track, or you can put a bunch of numbers (put them all between two quotes though) to process a bunch of tracks.

Here’s the program:

    #!/bin/bash
    for i in $1
    do
      tccat -i /dev/dvd -T $i,-1 > track_$i.vob
      mplayer -vo null -alang en -aid 128 -ao pcm:file=$i.wav track_$i.vob
      rm track_$i.vob
      mv audiodump.wav $i.wav
      lame $i.wav $i.mp3
      rm $i.wav
    done

I saved this as a file called extract_mp3_from_dvd_track and it can be executed thusly:

    extract_mp3_from_dvd_track 3
    extract_mp3_from_dvd_track '1 2 3 4 5 6'

Make sure you’ve got at least 2GB of free disk space on whatever drive you run this on because the temporary VOB file is pretty big.


Please if you found this post helpful or have questions.