Nowadays we are surrounded by devices able to read digital audio, and there are many services such as Spotify which allow to stream content legally. However if you like to buy music on physical support (compact disc), you may want to extract the audio tracks so they can be used on your smartphone or favorite device, or just for backup purposes. There are man tools on Linux which can be used to accomplish such task, but in the vast majority of cases they are just frontend to cdparanoia. In this tutorial we will learn how to use this tool.
In this tutorial you will learn:
- How to install cdparanoia on the most used Linux distributions
- How to retrieve drive information
- How to rip all the audio tracks from a compact disc
- How to rip specific tracks and/or a specific segment of a track
- How to pipe the output of cdparanoia to tools like flac or lame to compress the audio tracks
Software requirements and conventions used
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Distribution independent |
Software | cdparanoia |
Other | Root permissions to install the package |
Conventions | # – requires given linux-commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux-commands to be executed as a regular non-privileged user |
Installation
Cdparanoia is a command line CD ripper application which can work on many Unix-based operating systems, and so also on Linux. It is open source and developed with the aim to be very accurate, so to produce the best possible rips. The software is available in the official repositories of the most used Linux distributions. To install it on Archlinux, for example, we can use the pacman
package manager (cdparanoia is part of the “extra” repository). We can run:
$ sudo pacman -Sy cdparanoia
On recent versions of Fedora, we can install it via dnf
, by issuing the following command:
$ sudo dnf install cdparanoia
On Debian and its derivatives, as always, we can use one of the available package managers, such as apt-get
:
$ sudo apt-get update && sudo apt-get install cdparanoia
Retrieving drive information
The first thing we want to do when using cdparanoia is to analyze the drive we are using to read the audio CD. To accomplish our task, all we want to do is to invoke the application with the -A
option (short version of --anlyze-drive
). Cdparanoia should be able to find the drive automatically:
$ cdparanoia -A
Depending on the speed of the drive and of the type of connection, the command above could take a while to finish. The application should automatically retrieve information about the drive in use and display them on screen:
cdparanoia III release 10.2 (September 11, 2008) Using cdda library version: 10.2 Using paranoia library version: 10.2 Checking /dev/cdrom for cdrom... Testing /dev/cdrom for SCSI/MMC interface SG_IO device: /dev/sr0 CDROM model sensed sensed: Slimtype DVD A DS8A5SH XAA2 Checking for SCSI emulation... Drive is ATAPI (using SG_IO host adaptor emulation) Checking for MMC style command set... Drive is MMC style DMA scatter/gather table entries: 1 table entry size: 122880 bytes maximum theoretical transfer: 52 sectors Setting default read size to 27 sectors (63504 bytes). Verifying CDDA command set... Expected command set reads OK. Attempting to set cdrom to full speed... drive returned OK. =================== Checking drive cache/timing behavior =================== Seek/read timing: [45:48.06]: 36ms seek, 13.48ms/sec read [1.0x] [40:00.33]: 35ms seek, 1.30ms/sec read [10.3x] [30:00.33]: 59ms seek, 25.48ms/sec read [0.5x] [20:00.33]: 81ms seek, 13.90ms/sec read [1.0x] [10:00.33]: 70ms seek, 26.06ms/sec read [0.5x] [00:00.33]: 93ms seek, 26.82ms/sec read [0.5x] Analyzing cache behavior... Drive does not cache nonlinear access Drive tests OK with Paranoia.
Ripping a CD
To start ripping the tracks from a CD, we can now run the application and use the -B
or --batch
option. This will make so that all the tracks of the CD are extracted and saved on disk with the track#
prefix, named progressively from track 0
onwards. It’s a good idea to also use the -X
option, which is the short form for --abort-on-skip
: this option modifies the application behavior so that the ripping process is aborted if imperfections are found (for example due to a scratch on the disc surface).
$ cdparanoia -XB
The progress of each track extraction will be displayed on screen:
cdparanoia III release 10.2 (September 11, 2008) Ripping from sector 0 (track 0 [0:00.00]) to sector 207144 (track 9 [7:25.49]) outputting to track00.cdda.wav (== PROGRESS == [ | 000032 00 ] == :^D * ==)
Specifying the tracks format
By default the ripped tracks will be saved in the user current working directory, using the .wav
extension. This is not the only available format, since cdparanoia is able to save tracks also in the AIFF
, AIFF-C
or raw
formats. How can we
specify those alternatives? All we have to do is to invoke the program using, respectively, the -f
(--output-aiff
), the -a
(--output-aifc
) or -p
(--output-raw
) options. To rip all the CD tracks in the AIFF
format, for example, we would run:
$ cdparanoia -fXB
Extract only specific tracks or specific part of a track
In the previous examples we invoked cdparanoia to extract all the CD tracks; what if we want to extract only a specific track, or a range of tracks? Extracting only a specific track is very simple, we just have to specify its
number when invoking cdparanoia. To extract only track n. 1, for example, we would run:
$ cdparanoia -XB 1
To specify a range, instead, we can separate the track numbers with an hyphen. To extract tracks from 2 to 4, for example, we would invoke the application this way:
$ cdparanoia -XB 2-4
If we want to extract from the first track to a specific one, it’s enough to specify only the latter, so to extract from the beginning to the fourth track, we would run:
$ cdparanoia -XB -- -4
Cdparanoia let us rip only specific parts of a track. The syntax to use is quite simple: we specify the track that should be ripped, and then between brackets, the fine-grained offset:
1[ww:xx:yy.zz]
Where ww
are the hours, xx
are the minutes, yy
are the seconds and zz
are the sectors to be ripped. If a field is 0
doesn’t need to be specified. Let’s see an example. Say we want to extract from the minute 5:37
to the minute 5:45
of the first track of the album; we would invoke cdparanoia like that:
$ cdparanoia -XB 1[5:37]-1[5:45]
Encoding ripped tracks
Respecting the Unix philosophy of “do one thing and do it right”, cdparanoia doesn’t care about encoding extracted tracks in compressed formats such as ogg, mp3 (lossless) or flac. Performing such encodings is however quite simple using the appropriate tools. Cdparanoia have the capability of ripping tracks directly to standard output, therefore we can pipe it through other programs which will perform the conversion. For example, say we want to save the tracks and convert them to flac, using the flac encoder; we would run:
$ cdparanoia -X 1 - | flac - -o track01.flac
In the above command we invoke cdparanoia by specifying the track number to be extracted and the -
symbol to instruct the program to put its stream directly to stdout (standard output). We than used a pipe to use cdparanoia output as the flac encoder standard input. To instruct the latter to read from its standard input we used the -
symbol again, than we used the -o
option to specify the name that should be used for the final file.
To compress the file in .mp3
format, we can use the lame application instead. We would run:
$ cdparanoia -X 1 - | lame -b 320 - track01.mp3
We piped the output of cdparanoia to the lame application which is used to create mp3 audio files. Since mp3 is a lossy format, we used the -b
option of the latter to specify a fixed bitrate of 320kbps
and, again, the -
symbol to
instruct the application to read from its standard input; finally, we provided the name of the output file, just like in the previous example.
To encode extracted tracks in the .ogg
format, we can use the oggenc application, which is part of the vorbis-tools suite. In the following example we encode the audio specifying that an average bitrate of 256 kbps
should be used, and that the output file should be named track01.ogg
:
$ cdparanoia -X 1 - | oggenc - -b 256 -o track01.ogg
Conclusions
In this tutorial we learned how to rip audio CDs using the cdparanoia application. We learned how to extract all the audio tracks from a compact disc, how to extract only specific tracks or even specific segment of a track. By default cdparanoia extracts the track using the .wav
format, but we learned how to compress the application output with other utilities as flac
, lame
and oggenc
to encode the stream respectively to the .flac
, .mp3
and .ogg
formats.