Ripping DVD audio to ogg in Ubuntu

Hello truth seekers! Here is my definitive guide to converting DVD audio to ogg encoded audio files in Ubuntu Linux. This method was used in Dapper and Breezy.

Tools

I used a combination of acidrip, ffmpeg, and oggenc to do the ripping. All are available through apt.

sudo aptitude install acidrip
sudo aptitude install ffmpeg
sudo aptitude install vorbis-tools

Method

First I extracted each chapter to an avi file using Acidrip. On the Video tab I set the Codec to “copy”. On the General tab I set the audio codec to “pcm” and the gain to 18 (this can be any number, experiment to see what works for you). Then I used the preview tab to check the audio levels. Then I queued up all the chapters and started ripping.

Once the avi files were made I used the following ffmpeg command to extract the audio to a wav file.

ffmpeg -i filename.avi filename.wav

You can create a bash script to do this for you, but don’t bother because I’ve already done it.

#!/bin/sh
for i in *.avi
do
  ffmpeg -i $i `basename $i .avi`.wav
done

Once I had done this, I used oggenc to make ogg files.

oggenc -q6 filename.wav -o filename.ogg

The -q6 option sets the ogg quality to 6. Most people use 4 or 5 which are a little more lossy. I prefer a setting of 6 to give me a higher quality with a file size that is still reasonable. Here is another bash script that takes care of this step for you.

#!/bin/sh
for i in *.wav
do
  oggenc -q6 $i -o `basename $i .wav`.ogg
done

Conclusion

Now you have ogg files created from you DVD that you can edit or listen to on your ogg player. This method can also be used to create mp3 files using lame.

2 comments

  1. J.B. Nicholson-Owens

    If you have a lot of WAV files to encode, a for loop will fail (too many arguments). Also, the for loop will not descend recursively into subdirectories. This could be handy if you have an entire jukebox you want to convert and everything is arranged in directories (perhaps you just ripped your CD collection into a series of directories named after artists and CD titles).

    Fortunately find with xargs scales up far better and can handle the recursion without problem:

    find . -maxdepth 1 -iname ‘*.wav’ -print0 | xargs -0 oggenc -q6

    You’ll notice I didn’t bother computing the new name (“foo.wav” becomes “foo.ogg”). This is because oggenc already encodes “foo.wav” as “foo.ogg”.

    I used -print0 and -0 on xargs to properly handle pathnames with spaces.

    It’s trivial to change this command to do as you wish. You can have the WAV file removed after successful encoding. For this, you might want to make a shell script that only handles one file (specified via argument), checks oggenc’s return code, and the existence of the output file before removing the source WAV file. Then call that script from xargs instead of calling oggenc directly. I leave that as an exercise for the reader.

    If you want the recursion to find all *.wav files starting from the current directory, delete “-maxdepth 1″.

  2. J.B. Nicholson-Owens

    I guess I should have simplified that a bit before posting.

    The jist of my first post applies to both of the for loops, not just the audio encoding: use find and xargs for big jobs or jobs where you’re dealing with arbitrary numbers of objects.

    The task here is twofold:

    1. Do the entire movie file -> Ogg Vorbis audio file transcoding completely and correctly for one file. Make a script for this. Later on, consider enhancing this script with more features (deleting temp files, logging, etc.).

    2. Call the aforementioned script with xargs as I illustrated before:

    find . -maxdepth 1 -iname ‘*.avi’ -print0 | xargs -0I{} /path/to/script ‘{}’

    and let the computer work for a long time doing all the transcoding, leaving Ogg Vorbis files alongside the corresponding movie files.

    The -I option on xargs lets you position the argument where you wish.

    find and xargs are a far better way to make this scale up than using for loops in the shell (I like GNU find and GNU xargs because they’re free software and ever so flexible).

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>