Jump to content

Rip Audio CDs

From ArchWiki

Music is usually stored on audio CDs in an uncompressed format which requires a lot of space (e.g. 700MiB for only 80 minutes of audio). CD rippers are designed to extract ("rip") the raw digital audio (in a format commonly called CDDA) from a compact disc to a file or other output.

Extracting the audio from the CD usually involves compressing it so that it requires less space using either lossless compression which provides the same quality at roughly half the size (e.g. APE and FLAC) or lossy compression providing lower quality at roughly a tenth the size (e.g. MP3 and OGG).

Ripping

From physical discs

See Optical disc drive#Ripping for a list of available software. For example, to extract audio with the cdrtools package:

$ cdda2wav -vall cddb=-1 speed=4 -paranoia paraopts=proof -B -D /dev/sr0

Some CD rippers support burning audio to a CD and transcoding on-the-fly (e.g. cdda2mp3).

Note By default, cdda2wav uses freedb.freedb.org as its Compact Disc Database Protocol (cddbp, wikipedia:cddb) server to look up CDs. Freedb.org was shut down on May 28th 2020 and as of 13th of June 2020, this URL used for lookups no longer seems to operate (see Wikipedia:Freedb#History). An alternative cddbp service provided by gnudb.org does exist and the parameters cddbp-server and cddbp-port could be used to access that instead.

To allow cdda2wav to create CUE files, you must also specify -t all to switch cdda2wav into a mode that creates a single audio data file for the whole CD.

Alternatively, to create a bin and cue file pair from an audio CD, use cdrdao. For example:

$ cdrdao read-cd --read-raw --driver generic-mmc:0x20000 --datafile cdimage.bin cdimage.toc && toc2cue cdimage.toc cdimage.cue

The cue file generated by this method is not the same as some may expect from tools like EAC. To convert the cdrdao formatted cue files to a "standard" cue file, try yatoc2cueAUR.

From image files

Sometimes rather than a physical disc, only an image is available. The audio tracks can still be extracted from image files.

The bchunk program can extract data and audio tracks from a .bin / .cue pair. This example will save each data track as outputXX.iso and each audio track as outputXX.wav where XX is the track number:

$ bchunk -w image.bin image.cue output

Post-processing

Tag editors

For some examples of audio tag editors see List of applications/Multimedia#Audio tag editors.

Converting to other formats

Re-encoding to another format can be done with lame, flac or FFmpeg. For example, to convert the output raw audio files from #Ripping to highest quality variable bitrate MP3:

$ lame -V0 input.wav

To convert them to FLAC instead:

$ flac input.wav

Tips and tricks

Testing the ease, or difficulty, of ripping

As a test for the degree of difficulty you would face for a specific extraction process, one might test if they can rip only the audio data of the first track:

$ cdparanoia --batch --log-debug -- -1

Which will create the cdparanoia.log log file. And, if successful, a track01.cdda.wav file. See cdparanoia(1) for other options.

Converting that to MP3 can be accomplished with:

$ ffmpeg -i track01.cdda.wav -vn -ar 44100 -ac 2 -b:a 192k output-file.mp3

A short description of that ffmpeg line is here.

Recovery

There is no way to connect to an audio CD via ddrescue, because it is a CDDA stream and not a block device for reading by the kernel's ioctl system calls.

For audio CDs (CD-DA), cdparanoia can extract individual tracks to PCM audio files. When dealing with damaged discs or interrupted extraction, a chunk-based workflow can preserve successfully extracted data and retry only incomplete sections.

A custom Bash script can automate this process by splitting each track into sector ranges, extracting each range separately, validating its expected size, and concatenating the resulting raw PCM data. Completed chunks are retained on disk and skipped when the script is run again. If a chunk cannot be extracted successfully after retries, the script can substitute silence to preserve the track duration; such chunks should be reviewed rather than treated as successfully recovered audio.

The resulting files contain raw PCM audio and do not include WAV headers or track metadata. For example, a raw file can be converted to WAV with:

$ ffmpeg -f s16le -ar 44100 -ac 2 -i track01.raw track01.wav

This approach is intended for extracting audio tracks, not for creating a bit-for-bit image of an entire disc. It does not preserve the disc's complete layout, subchannel data, or other non-audio structures, and a correct output size does not guarantee error-free audio.

See also

  • RIAA allow backup of physically obtained media under these conditions.
  • lame(1) manual page, for options and presets.
  • Hydrogenaudio's description of recommended LAME encoder settings.