Ripping CDs to FLAC format (on Linux)

I’ve several hundred CDs which I’m in the process of (re)ripping to the FLAC audio format from the current mix of mp3 and ogg format files.

FLAC (Free Lossless Audio Codec) is a high quality audio codec. Unlike mp3 or ogg encodings which reduce the bit rates and provide a measure of filtering on the outlying frequencies, FLAC provides a compressed lossless encoding of your music.  (You could think of this like the difference between a zip file, which compresses the files inside them, but allows you to get the original back, and JPG encoding for photos. When you shrink an image using jpg , information is lost, so you can’t expand it back to the original size with the same quality).

FLAC vs MP3/Ogg

For portable media devices MP3 and ogg files are fine – the environment I use mine in, and the headphones they come with means that these formats are perfectly adequate when out and about.

However playing the music through a Hi-Fi system means that you are losing some of the full quality of your music.  You can hear the difference by playing the original CD and a ripped file.

I have an Onkyo TX-NR509 AV receiver which is network ready and can play a range of audio formats.  Coupled to some quality Tannoy speakers, it seemed a shame to play music that doesn’t make full use of its abilities.

The final piece of the puzzle is the fact that storage space is cheap now, so when I originally ripped to MP3 I had less disk space available.  Now using my FreeNas box, I have plenty of space and I can share out the music using DLNA, so I felt it was worth re-ripping my collection.

More information about different audio formats can be found at here on Wikipedia which provides a neat comparison of the different formats.

Required Utilities

I’m using Linux, so I have a choice of ripping programs.  The two I prefer are k3b and abcde. I also use metaflac.

  • k3b is part of the KDE desktop environment.  This is a good choice when you don’t have a CDDB file (or it can’t retrieve one), but the CD has CD text.
  • abcde is a shell script that uses several different programs to perform the ripping/CDDB or MusicBrainz querying/encoding.  The nice thing with this is that you can set up a lot of defaults in the configuration file, so I normally just have to respond to a couple of prompts .
  • metaflac This is a command line utility than perform many operations of a FLAC file. I just use it to add the cover image into the file.

Installing abcde

My distribution, OpenSuse, automatically installs the dependencies for this utility (eject, lame, flac, cdparanoia). You may need to do this manually if your distribution doesn’t have it ready-packaged for you.

My Workflow: Ripping CD to FLAC format

My preferred option is to use abcde as it requires less manual input. If it cannot retrieve the track listings from CDDB or musicbrainz, I use k3b as the fall-back.

Ripping the file using abcde

  1. Open a console window.
  2. Pop the CD in the drive
  3. type abcde and accept the prompts. If there are several alternative CDDB entries you will be prompted to choose one.  You are given the option to edit the file (optional).  If the CD appears to be multi-artist, then you’ll be prompted for the artist and track format.

Here’s an example session:

me@linux-121a:~/music> abcde
Grabbing entire CD - tracks: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
---- Various Artists / Cafe Cubana - Cigars, Cars And Cuban Bars ----
Genre: Latin
1: Septeto Nacional & Ignacio Pineiro / Carei Que Errs Mir
2: Compay Segundo / Juramento
3: Grupo Raison / Gurjira Guantanamera
4: Omara Portuando / Nosotros
5: Beny More / Curndo Quierrs Volver
6: Los Zafiros / Mis Sentimientos
7: Elena Burke / Amor De Mis Amores
8: Orquesta Aragon & Elena Burke / Son Al Son
9: Beny More / Donde Estabas Tu
10: Candido Fabre Y Su Banda / Dame Tu Amor Guantanamera
11: Los Van Van / Cuentame
12: Compay Segundo / Te Apartas De Mi
13: Septeto Nacional & Ignacio Pineiro / La Cumbancha
14: Compay Segundo / Me Diras Que Sabroso
15: Septeto Nacional / Quien Sera Mi Bien
16: Omara Portuondo / Alli
Edit selected CDDB data? [y/n] (n): n
Looks like a Multi-Artist CD
1) Artist / Title
2) Artist - Title
3) Title / Artist
4) Title - Artist
5) Artist: Title
6) Title (Artist)
7) This is a single-artist CD
Which style of multiple artist entries is it? [1-7] (1): 1
Grabbing track 01: Septeto Nacional & Ignacio Pineiro / Carei Que Errs Mir...
cdparanoia III release 10.2 (September 11, 2008)

Ripping from sector       0 (track  1 [0:00.00])
          to sector   12081 (track  1 [2:41.06])

outputting to /tmp/wavout/abcde.de0e6710/track01.wav

The ripping will start and a progress bar will be shown.  The disc will eject when it has finished.

(the total number of key presses here was 7 “abcde” + enter, then “n” + enter.)

Ripping the file using k3b

This is a slower process as you have multiple dialogue boxes to navigate.  Once the CD is inserted, go to the Device->Media Info menu to see if there is any CD text on the CD (which will save some typing).

K3B Media Info window
K3B Media Info window

There is CD Text on this album, so K3B can use this to rip and label the tracks.

Go to Tools->Rip Audio CD.  Click on Edit Album Info and set the year and genre and category fields.

k3b Edit Album Info

Then press the Start Ripping button to bring up the ripping dialogue. The first tab is settings.  Here select the format you want to rip to, and the location to rip the files to.

k3b ripping dialogue settings Tab
Settings tab

The file name is shown as the default with the folder called by both the album name and artist. I prefer to have the top level folder with the artist name and the

My preferred format is to have the top folder with the artist name and their albums in folders under that, so I need to go to the File Naming tab.

k3b ripping dialog File Naming tabI replace the default string with:

%A/%T/%n.!a='%A'{%a - }%t

and then press the Start Ripping button.

You can see there is a lot more work involved in using k3b, which is why I prefer to use abcde when I can.

Adding the Album Image to the File

I like to embed the album artwork into the file.  You’ll have to locate the artwork yourself, I had most of mine already, all called cover.jpg sitting in the old directory, so I just copied this across to the new directory and used metaflac to add the image into the audio file.

> for f in *flac ; do  metaflac --import-picture-from=cover.jpg "$f" ; done

(Metaflac can add multiple images and do all sorts of other great things; metaflac --help will tell you more.)

 The abcde Configuration file (abcde.conf)

This is stored in ~/abcde.conf.  This is a minimal configuration that rips to FLAC by default and ejects the disc after ripping.  I use CDDB, rather than musicbrainz.

#
# defaults for abcde
#
INTERACTIVE=y
ENCNICE=2
READNICE=1
MAXPROCS=4

OUTPUTDIR=~/music
WAVOUTPUTDIR=/tmp/wavout
KEEPWAVS=no

OUTPUTTYPE=flac

# always put leading 0 in tracknum
PADTRACKS=y
OUTPUTFORMAT='${ARTISTFILE}/${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
VAOUTPUTFORMAT='Various/${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'
#
# generate a playlist automatically.
#
PLAYLISTFORMAT=´${ARTISTFILE}-${ALBUMFILE}.m3u´

CDDBMETHOD=cddb 
CDDBURL=http://freedb.freedb.org

#CDDBMETHOD=musicbrainz
#CDDBURL=www.musicbrainz.org

CDDBLOCALDIR=/public/music/cddb/
CDDBLOCALRECURSIVE=y
CDDBCOPYLOCAL=y
HELLOINFO=mylogin@mydomain.tld
CDDBLOCALPOLICY=net
CDDBUSELOCAL=y

# device
CDROM=/dev/cdrom
EJECTCD=y
EJECT=/usr/bin/eject

COMMENT=''
#
# nice values - keep this low priority
#
ENCNICE=15
READNICE=15
DISTMP3NICE=15

Audio Hardware

I’m a fan of Richer Sounds who are a UK audio and hi-fi specialist retailer.

The Tannoy Speakers were still available at the time of writing, but the AV receiver has been superseded by newer models since then.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.