Linux Rip and Encode Audio CDs Commands - nixCraft

Linux Rip and Encode Audio CDs Commands

See all GNU/Linux related FAQ
How do I rip audio CD under Linux operating systems? How do I convert .wav file to .mp3 or .ogg? How do I use encoders under Linux? How do I get music from very old and roughed CD’s from my school/wedding music under Linux operating systems using GUI tools?

To rip audio CDs under Linux operating system you need to use the following command line tools:

  1. cdparanoia – an audio CD reading and extraction utility which includes extra data verification features.
  2. lame – LAME is a program which can be used to create compressed audio files (encode) i.e. create mp3 files so that audio files can be played back by popular MP3 players.
  3. oggenc – oggenc is a program which encode audio into the Ogg Vorbis format.
  4. ripperx and K3b – GUI tools for ripping and encoding audio CDs.

This page shows how to rip audio CDs on Linux operating system using both GUI and the CLI methods.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux terminal
Category Package Manager
OS compatibility AlmaLinux Alpine Arch Debian Fedora Linux Mint openSUSE Pop!_OS RHEL Rocky Stream SUSE Ubuntu
Est. reading time 8 minutes
Please note that you can install the following tools on macOS Unix, FreeBSD and other oses too. Apple macOS/OS X Unix users, first install Homebrew on Mac OS to use the brew package manager and then use the brew command to install them as per your needs.

Linux Rip and Encode Audio CDs

To rip audio CDs, first rip cd (copy audio CD contents track) and store them as a file (as track01.wav,track02.wav) in a raw format. However, .wav (raw form) files are big. You need to save disk space by converting and compressing .wav to .mp3 or .ogg lossy format. It is done using lame or oggenc encoders. CD rippers designed to extract the raw digital audio from a compact disc to a file.

Prerequisite
By default, cdparanoia, lame, oggenc, ripperx, and k3b command may not be installed on your system. Hence, use the apk command on Alpine Linux, dnf command/yum command on RHEL & co, apt command/apt-get command on Debian, Ubuntu & co, zypper command on SUSE/OpenSUSE, pacman command on Arch Linux to install the cdparanoia, lame, oggenc, ripperx, and k3b.

Get Track and CDDA Information

Type the following command to get detailed information about drive and audio CD:
$ cdparanoia -vsQ
Sample Outputs:

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: TSSTcorp CD/DVDW SH-S182D SB04 
 
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: 131072 bytes
	maximum theoretical transfer: 55 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.
 
Table of contents (audio tracks only):
track        length               begin        copy pre ch
===========================================================
  1.    15485 [03:26.35]        0 [00:00.00]    no   no  2
  2.    20316 [04:30.66]    15485 [03:26.35]    no   no  2
  3.    23579 [05:14.29]    35801 [07:57.26]    no   no  2
  4.    17344 [03:51.19]    59380 [13:11.55]    no   no  2
  5.    13928 [03:05.53]    76724 [17:02.74]    no   no  2
  6.    14954 [03:19.29]    90652 [20:08.52]    no   no  2
  7.    18415 [04:05.40]   105606 [23:28.06]    no   no  2
  8.    13386 [02:58.36]   124021 [27:33.46]    no   no  2
  9.    17697 [03:55.72]   137407 [30:32.07]    no   no  2
 10.    22469 [04:59.44]   155104 [34:28.04]    no   no  2
 11.    16163 [03:35.38]   177573 [39:27.48]    no   no  2
 12.    15423 [03:25.48]   193736 [43:03.11]    no   no  2
 13.    18116 [04:01.41]   209159 [46:28.59]    no   no  2
 14.    20106 [04:28.06]   227275 [50:30.25]    no   no  2
 15.    18373 [04:04.73]   247381 [54:58.31]    no   no  2
 16.    26250 [05:50.00]   265754 [59:03.29]    no   no  2
 17.    15166 [03:22.16]   292004 [64:53.29]    no   no  2
 18.    18664 [04:08.64]   307170 [68:15.45]    no   no  2
TOTAL  325834 [72:24.34]    (audio only)

Step 1 – Rip Audio CD and Create .WAV Track Files

Open a shell prompt and type the following command to rip all tracks i.e. extract an entire disc, putting each track in a separate file, enter:
$ cdparanoia -B
Sample outputs:

cdparanoia III release 10.2 (September 11, 2008)
 
 
Ripping from sector       0 (track  1 [0:00.00])
	  to sector  325833 (track 18 [4:08.63])
 
outputting to track01.cdda.wav
 
 (== PROGRESS == [                              | 015484 00 ] == :^D * ==)   
 
outputting to track02.cdda.wav
 
 (== PROGRESS == [                              | 035800 00 ] == :^D * ==)
.....
...
...
outputting to track18.cdda.wav
 
 (== PROGRESS == [                              | 325833 00 ] == :^D * ==)   
 
Done.

You can see all your .wav files with the help of ls command:
$ ls
Sample outputs:

track01.cdda.wav  track04.cdda.wav  track07.cdda.wav  track10.cdda.wav  track13.cdda.wav  track16.cdda.wav
track02.cdda.wav  track05.cdda.wav  track08.cdda.wav  track11.cdda.wav  track14.cdda.wav  track17.cdda.wav
track03.cdda.wav  track06.cdda.wav  track09.cdda.wav  track12.cdda.wav  track15.cdda.wav  track18.cdda.wav

The default output format is .wav. You can set to .aift or .raw depending on whether the option -a, -r or, -R is used:
$ cdparanoia -aB # use .aift format
$ cdparanoia -rB # use .raw format

To extract up to and including track 5, putting each track in a separate file, enter:
$ cdparanoia -B -- -5
To extract only first two tracks type the following command, enter:
$ cdparanoia -B -- 1-2
Sample outputs:

cdparanoia III release 10.2 (September 11, 2008)
 
 
Ripping from sector       0 (track  1 [0:00.00])
	  to sector   35800 (track  2 [4:30.65])
 
outputting to track01.cdda.wav
 
 (== PROGRESS == [                              | 015484 00 ] == :^D * ==)   
 
outputting to track02.cdda.wav
 
 (== PROGRESS == [                              | 035800 00 ] == :^D * ==)   
 
Done.

Finally, you can extract from track 1, time 0:13.13 to 1:13.00, enter:
$ cdparanoia "1[:13.13]-1[1:13]"

Step 2 – Encode To .MP3 Format

To create mp3 audio file, enter:
$ lame track01.cdda.wav
Sample outputs:

Fig.01: Linux create mp3 audio files

Fig.01: Linux create mp3 audio files

You can set mode using the -m option:
lame -m Mode -b rate input.wav
Where Mode can be any one of the following:

  1. s : simple stereo
  2. j : joint stereo
  3. f : forced MS stereo
  4. d : dual mono
  5. m : mono

Setting Up Bit Rates

Several bit rates are specified in the MPEG-1 Audio Layer III standard: 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256 and 320 kbit/s, and the available sampling frequencies are 32, 44.1 and 48 kHz. Additional extensions were defined in MPEG-2 Audio Layer III: bit rates 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 kbit/s and sampling frequencies 16, 22.05 and 24 kHz. The -b option can be used as follows to set 160 bit rate:
$ lame -b 160 track01.cdda.wav
You can use the following bash for loop command to encode all tracks:
$ for t in track{01..18}*.wav; do lame $t; done

Step 3 – Encode To .OGG Format

Vorbis is a free software / open source project headed by the Xiph.Org Foundation. The project produces an audio format specification and software implementation (codec) for lossy audio compression:
$ oggenc track01.cdda.wav
Sample outputs:

Fig.02: Linux create .ogg audio files

Fig.02: Linux create .ogg audio files

You can set the Ogg Vorbis stream to output file name with the -o option (only valid if a single input file is specified):
$ oggenc track01.cdda.wav -o output01.ogg
Set and encode bitrate at 500 kbit/s, enter:
$ oggenc -b 500 track01.cdda.wav -o output01.ogg
Sample outputs:

Encoding "track01.cdda.wav" to 
         "output.ogg" 
at approximate bitrate 500 kbps (VBR encoding enabled)
	[100.0%] [ 0m00s remaining] | 
 
Done encoding file "output.ogg"
 
	File length:  3m 26.0s
	Elapsed time: 0m 08.1s
	Rate:         25.6000
	Average bitrate: 396.2 kb/s

You can specifying a maximum and average bitrate, and enforcing these:
$ oggenc input.wav --managed -b 128 -M 160 -o output.ogg
Set quality rather than bitrate (to a very high quality mode):
$ oggenc input.wav -q 6 -o output.ogg
Please note that encoding quality is set between -1 (very low) and 10 (very high). To Downsampling and downmixing to 11 kHz mono before encoding:
$ oggenc --resample 11025 --downmix input.wav -q 1 -o output.ogg
You can add some info about the track:
$ oggenc input.wav -t "Can I Trouch You...There?" -a "M.Bolton" -l "Instrumental Love Songs" -c "Other Info Here"

Say Hello To GUI Tools

You can use various GUI tools for ripping and encoding audio CD tracks under Linux operating systems.

ripperX

ripperX is graphical (GTK i.e. Gnome) frontend for ripping and OGG/FLAC/MP3 encoding CD tracks. To install it type the apt command or apt-get command:
$ sudo apt-get install ripperx
$ ripperx

Sample outputs:

Fig.03: ripperX - Ripping and OGG/FLAC/MP3 Encoding CD Tracks

Fig.03: ripperX - Ripping and OGG/FLAC/MP3 Encoding CD Tracks

Setup required fields and hit Go! button to start ripping and encoding:
Fig.04: RipperX in Action

Fig.04: RipperX in Action

k3b

K3b lets you burn CDs and DVDs. It also allows you to rip audio cds. To install k3b, enter:
$ sudo yum install k3b # redhat and friends via RPMForge k3b-extra repo
OR
$ sudo apt-get install k3b
Next, start K3b, and click on Tools > Rip Audio Cd… (Or click on Start Ripping button)

Fig.05: Rip audio CDs using K3B Application

Fig.05: Rip audio CDs using K3B Application

You can set output format and other settings before ripping audio CDs:
Fig.06: K3b Set Audio CD Ripping Options

Fig.06: K3b Set Audio CD Ripping Options

Fig.07: K3b in Action

Linux Ripping Audio Tracks - K3b - MP3 - OGG Encoding

Further readings:

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠

I'm Vivek Gite. I write about Linux, IT, and open source. Subscribe to my RSS feed or email newsletter for updates. This site is self-funded and ad-free 🙌. Want to support nixCraft? You can help through Patreon, PayPal, or merchandise store.


13 comments… add one
  • Sean Jul 8, 2014 @ 7:22

    No mention of FLAC. Fail.

  • Jasper Apr 16, 2015 @ 11:13

    Thanks, works nicely on a Mac with MacPorts as well (Except for the GUI tools). . I’d forgotten how to extract data from an audio CD.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.