Screaming Stone Design

How to rip a CD to MP3 with Linux

Technologies: Linux, BASH

For this tutorial I will be using Ubuntu, firstly because it is one of the most popular versions of Linux and secondly because it is the one that I use. The installation method shown should be the same for other versions of Linux based on Debian. The actual ripping method should be the same for all versions of Linux.

Without doubt there will be many nice binary executables (programs) out there for Ubuntu (or similar) with beautifully designed GUIs to allow you to rip your CDs to MP3 but this tutorial will be using the terminal window and 2 programs which will run in the terminal: CDParanoia and Lame, both of which we may need to install.

To begin the whole process we will need to open a terminal window - this varies according to which flavour of Linux you are using.

To open a new terminal in Ubuntu hold down the [CTRL] and [ALT] keys and press [t].

Once you have a new terminal window open you need to begin the installation process by typing the following command string:

sudo apt-get update

Once you have done that you need to press the [enter] key - the same goes goes for every command shown below, except for those given in italics which are merely displaying syntax or structure.

You will be asked for your password, as the actions you are taking require administration privileges, but you should only be asked for it once at the beginning.

The above quickly updates your system with any new updates available and, unlike Windows, you won't need to reboot your computer for the changes to take effect.

Next you need to install a program called CDParanoia which will rip your CD to your hard drive in WAV format:

sudo apt-get install cdparanoia

CDParanoia is super fussy about copying the data from CDs and will perform careful error correction so it will usually do a better job than other software but at the cost of being much slower.

Next you need to install something to create MP3 files from your WAV files and for this the only realistic option is Lame:

sudo apt-get install lame

It is important to remember that the path shown in your terminal prompt is to location to which your files will be copied, so if you want them somewhere else, for example your Music folder, then you need to navigate there.

cd Music

Perhaps you might already have some MP3s and some WAVs in the folder and you don't want them to get confused with the new ones you are going to make so I recommend you make a new folder (such as “rip”):

mkdir rip

And then move into that folder:

cd rip

You should notice that your prompt has changed and now displays the folder you are working in.

Once that is done you can pop a CD into your computer's optical drive and begin the ripping process by typing the following:

cdparanoia -B

Please note that the option you add after the name of the program is a capital letter B.

Your computer will now rip all of the tracks to your working folder in WAV format.

Also note that occasionally a file will be created called track00.cdda.wav which is actually only a lead-in to the first track and it should be deleted.

Now you need to use Lame to create new MP3 files from the WAV files but it is important to note that Lame converts one file at a time and uses the following basic format:

lame (option) (option) infile outfile.mp3

The options you use really depend on the quality or size of output you want - the "standard" format, used by the likes of Amazon, has a constant bitrate of 128 kbps (kilobits per second) and is, quite honestly, total shit.

If you want to have a good quality version you can enjoy then use the following options:

lame -mj -V0 infile outfile.mp3

The first option, -m, tells Lame which mode to use when encoding the MP3, whether it should be mono or stereo.

In this case we are setting it to -mj which means it should have joint stereo.

The full list of modes is: (j)oint stereo, (s)imple stereo, (f)orced stereo, (d)ual-mono, (m)ono, (l)eft channel only, (r)ight channel only.

The second option, -V, tells Lame to encode the data at a variable bitrate instead of a constant bitrate and the number following it sets the quality level.

-V9 produces the smallest files but at the lowest quality whereas -V0 produces the largest files but at the highest quality.

-V0 achieves the same result as encoding at a constant bitrate of 320 kbps, the highest bitrate available, but produces smaller files.

As mentioned earlier Lame can process only one file at a time so to get around this you can convert the command given above to run in a loop:

for f in *.wav;
  do lame -mj -V0 "$f" "${f%.wav}.mp3";
done

What the above does is cycle through every WAV file in the current working folder and assigns its name to the variable f and then creates an MP3 file and uses the name of the WAV file as the name of the new MP3 file.

The command can be shortened to a single line:

for f in *.wav; do lame -mj -V2 "$f" "${f%.wav}.mp3"; done

Lame produces a pretty visual output and you can spend a moment enjoying it while your new MP3 files are created.

When it is finished you will need to remove all of the WAV files you created at the start of the process.

rm *.wav

Please note that the above command will delete all of the WAV files in the current working folder, which is why I recommended you should create a folder specifically for ripping to, otherwise you could end up deleting many files you did not intend to.

If you had to type out those commands every time you ripped a CD you would find it very tedious, so to get around this you should create a shell script.

The following is specific to Ubuntu so if you are going to use a different version of Linux you should use whatever command is appropriate to open a text editor available to you:

gedit ripper

This will open the G-Edit text editor and will attempt to open a text file called ripper and if it doesn't find a file with that name it will create one.

Enter the following text:

#!/usr/bin/env Bash
cd ~/Music/rip
cdparanoia -B
for f in *.wav; do lame -mj -V0 "$f" "${f%.wav}.mp3"; done
rm *.wav

Save the file and close G-Edit.

Next you can make this shell script “executable” with the following command in the terminal:

chmod +x ripper

You can then close terminal and move the file to your home folder because this is the folder which terminal always starts in when you run it and we want to make this as easy to use as possible.

Open a new terminal window by holding down the [CTRL] and [ALT] keys and press [t].

To run your shell script type the following:

./ripper

Please note that if you decide to rip your files to a different folder you should change this shell script to match the folders you are going to use and those folders should already exist.

Or, you could change the script so it creates the rip folder for you - there is enough information given in this tutorial for you to figure out how to do that.