Making CDs from a DVD soundtrack in Linux

Required software

Check that you have installed these packages (names as in Ubuntu).
  • mplayer
  • libdvdcss2
  • cdrdao

    Overview

  • Find out what is on the DVD.
  • Make a WAV file containing the soundtrack.
  • Make one or more TOC files indexing the WAV file.
  • Burn the CDs.

    Find out what is on the DVD

      mplayer dvd://1 -frames 0 -vo null -identify | grep ID_AUDIO 2> /dev/null 
    You will see something like
    ID_AUDIO_ID=160
    ID_AUDIO_ID=137
    ID_AUDIO_ID=160
    ID_AUDIO_FORMAT=65537
    ID_AUDIO_BITRATE=0
    ID_AUDIO_RATE=0
    ID_AUDIO_NCH=0
    ID_AUDIO_BITRATE=1536000
    ID_AUDIO_RATE=48000
    ID_AUDIO_NCH=2
    ID_AUDIO_CODEC=dvdpcm
    Note the last value of ID_AUDIO_ID that appears before ID_AUDIO_CODEC, in this case 160.
      mplayer dvd://1 -frames 0 -vo null -identify | grep CHAPTERS 2> /dev/null
    You will see something like
    ID_DVD_TITLE_1_CHAPTERS=18
    ID_DVD_TITLE_2_CHAPTERS=14
    CHAPTERS: 00:00:00,00:00:30,00:05:39,00:12:54,00:14:43,00:18:05,00:21:50,00:24:23,...
    Or maybe nothing at all.

    Make a WAV file containing the soundtrack

    The critical thing here is to make sure the WAV file is sampled at the standard CD rate of 44100 Hz, not at the standard DVD rate of 48000 Hz.
      mplayer dvd://1 -aid 160 -vc null -vo null -srate 44100 -ao pcm:fast:file=soundtrack.wav 
    Of course, you will put the correct ID_AUDIO_ID in place of 160, and your own name for this particular soundtrack in place of soundtrack.wav.

    Make one or more TOC files indexing the WAV file

    If you type man cdrdao, you will see somewhere:
        The  toc-file  describes what data is written to the CD-R and allows
        control over track/index positions, pre-gaps and sub-channel information.
            It is a simple text file, use your favorite text editor to create it.
    For a full discussion of what to put in the TOC file, you'll have to read what it says below that paragraph. Depending on how cool your CD player is, you may want to exploit just a few or quite a lot of the options. I'll discuss only three cases.

    Everything goes on one track of one CD

    This is the simplest case. The complete TOC file is:
    CD_DA
    TRACK AUDIO
    FILE "soundtrack.wav" 0

    Everything goes on two one-track CDs

    Suppose you want to break after 65 minutes, allowing an overlap of 30 seconds. You need to make two TOC files.
    CD_DA
    TRACK AUDIO
    FILE "soundtrack.wav" 0 65:30:00 
    Here, 65:30:00 is not the stopping point but the length of the track.
    CD_DA
    TRACK AUDIO
    FILE "soundtrack.wav" 65:00:00   

    A CD with tracks corresponding to DVD chapters

    For this you need to get starting times from the CHAPTERS information. There are two tricky little points here:
  • Although the timing information looks the same, the format is HH:MM:SS in CHAPTERS but MM:SS:FF for the TOC file. Thus 00:14:43 must become 14:43:00.
  • You need to calculate lengths from the difference between two successive starting times.

    I know you are good at mental arithmetic, but it may be a good idea to write a little program that takes CHAPTERS and produces a simple TOC file.

    You can always edit the TOC file later to delete unwanted tracks, put in performer/composer/arranger information etc. In the case of the CHAPTERS above, I happen to know that the first track belongs to the title screen so I omit it. The first few lines of the TOC file look like this:

    CD_DA
    TRACK AUDIO
    FILE "soundtrack.wav" 00:30:00 5:9:00
    TRACK AUDIO
    FILE "soundtrack.wav" 05:39:00 7:15:00 
    TRACK AUDIO
    FILE "soundtrack.wav" 12:54:00 1:49:00
    TRACK AUDIO
    FILE "soundtrack.wav" 14:43:00 3:22:00
    TRACK AUDIO
    FILE "soundtrack.wav" 18:05:00 3:45:00 
    TRACK AUDIO
    FILE "soundtrack.wav" 21:50:00 2:33:00 
    ...
    

    Burn the CDs

    For each TOC file, it's as simple as this:
    cdrdao write soundtrack1.toc