# HOWTO: ripping cds using FLAC

## supermihi

****

EDIT 28.3.2005

KAudiocreator seems a got alternative to grip for those guys using KDE, added pro's/con's of kaudiocreator/grip.

****

Hi,

I'm a fan of sound quality, and since I have some disc space free, I decided to rip some CDs to the free lossless audio codec (FLAC) instead of ogg vorbis which I was using before. The compression rate is for now about 50%, depending on the content of the audio file. Also I found that FLAC encodes VERY fast (~60-140x on my Athlon XP 2400+).

What annoyed me was that there seemed to be no really good, easy configurable ripping app that supported FLAC, especially with meta tags (flac seems to use Vorbis-style comments). The KDE audiocd:/ virtual interface is good for oggs and mp3s, and for some people FLAC, too (didn't got it working here; also it doesn't support renaming single fields of the comments if you want them changed).

For the guys using KDE I suggest kaudiocreator, which supports FLAC and is somewhat configurable.

Pro's:

- native FLAC support

- better implementation of the CDDB request

- easy to use

Con's:

- no way to change the ripping backend (cdparanoia etc.)

There's also sound-juicer which I never tried.

For the gnome users I recommend grip as CD ripping app supporting flac, but without metatags and having some other issues. The main issue of this Howto is getting grip configured to do a good FLAC encoding.

Pro's:

- Highly configurable

Con's:

- default configuration almost unusable

- must work a bit to get reasonable FLAC files

Both kaudiocreator and grip are kinda fast since they start to encode after the first track is ripped parallel to ripping the other tracks.

So, for anyone who wants to rip his CD collection to FLAC with automated, FreeDB-aided tagging, feel invited to follow these steps:

1. emerge grip (this could take a while if you don't have the gnome libraries installed already) and, of course, flac.

```
emerge -av flac grip
```

2. i suggest using cdda2wav instead of grip's standard ripper cdparanoia, since it is about six times faster (for me, at least, could be machine dependant). It's, in the cdrtools package (don't know why that), so

```
emerge cdrtools
```

3. Now it's time to start and configure grip. Go to Configuration->Rip->Ripper and set the Ripper to "cdda2wav" (if you want). Maybe you have to give the full path /usr/bin/cdda2wav for grip to understand it.

4. Go to Configuration->Encode->Encoder and choose "flac". Parse this line into "command line":

```
-V -o %m %w --tag=TITLE=%n --tag=ALBUM=%d --tag=ARTIST=%a --tag=YEAR=%y --tag=GENRE=%G --tag=TRACKNUMBER=%t
```

This takes the meta tags given by grip and parses them into the flac file. You also can add add a quality parameter (-0 up to - :Cool: , giving you a minimal smaller file by extremely increased encoding time.

5. Set your file naming format to what you want - %A for artist, %d for album title, %t for track number, %n for track title and %x for the appropriate file ending (.flac in this case).

6. It doesn't matter what you fill in at "ID3" since you gave the informations directly.

7. I suggest you to go to "Misc" and check "Do not lowercase filenames" and "do not change spaces to underscores", unless that's what you want. Also you might have to add some chars to "Characters not to strip in filenames", if you have non-ASCII content.

8. Press "Rip->Rip and Encode" to rip the whole cd or single tracks.

9. Enjoy quality!  :Smile: 

There are a lot of FLAC players around: flac123 for console output, the xmms-flac plugin, amarok, rhythmbox etc.

Please feel free to post your corrections or suggestions!

supermihi

----------

## Deathwing00

Moved from Multimedia.

----------

## Cintra

Many thanks for your Howto.. 

I had been wondering whether to try grip or not (all those gnome files...) and your howto has given me the required push  :Wink: 

Mvh

Edit: It worked fine with your setup, but to avoid hanging on a couple of faulty tracks I had to change to Grip Cdparanoia, 

which handled the errors with no problem. As you mentioned, encoding is very fast!

----------

## tkdfighter

Great guide! But I'm planning on backing up my cd collection to FLAC, burning it on dvd and then reencode the FLACs to mp3 using lame. The encoding is pretty strait forward, but how do I attach the ID3 information to the mp3s?

----------

## supermihi

 *Quote:*   

> how do I attach the ID3 information to the mp3s?

 

You can access the tags in the flac's with metaflac:

```
metaflac --show-vc-field=<FILED> file.flac
```

This will output, for example:

```
 TITLE=The Gentoo Song
```

Now you could use a script to transfer this information to lame -- according to 

```
lame --longhelp
```

 you can give the tag information for id3 as followin:

```
ID3 tag options:

    --tt <title>    audio/song title (max 30 chars for version 1 tag)

    --ta <artist>   audio/song artist (max 30 chars for version 1 tag)

    --tl <album>    audio/song album (max 30 chars for version 1 tag)

    --ty <year>     audio/song year of issue (1 to 9999)

    --tc <comment>  user-defined text (max 30 chars for v1 tag, 28 for v1.1)

    --tn <track>    audio/song track number (1 to 255, creates v1.1 tag)

    --tg <genre>    audio/song genre (name or number in list)

    --add-id3v2     force addition of version 2 tag

    --id3v1-only    add only a version 1 tag

    --id3v2-only    add only a version 2 tag

    --space-id3v1   pad version 1 tag with spaces instead of nulls

    --pad-id3v2     pad version 2 tag with extra 128 bytes

    --genre-list    print alphabetically sorted ID3 genre list and exit

    --ignore-tag-errors  ignore errors in values passed for tags

```

Now it's time for a little script that does this all by self. I'm not too versed in bash scripting but I'd try something like the following:

```

#!/bin/bash

for x in $* ; 

do TITLE=$(metaflac --show-vc-field=TITLE $x | sed s/TITLE=//g)

do GENRE=...

[...]

flac -d $x -o - | lame --tt TITLE --tg GENRE [...] $x.mp3     #dont know how to remove the .flac from $x :)

something like that should work
```

----------

## tkdfighter

Ok, thanks! Scripting isn't very hard, I can do that.

----------

## supermihi

Ok, I read your post to late, I finally managed to make some basic scripts for flac to mp3 and flac to ogg conversion:

For converting FLAC files to ogg vorbis:

```
#!/bin/bash

# /usr/local/bin/flac2ogg

# this script converts given flac files to ogg vorbis

QUALITY=4.5 # change if you want to

for x in $* ;

do TIT=$(metaflac --show-vc-field=TITLE $x | sed s/TITLE=//g)

   GEN=$(metaflac --show-vc-field=GENRE $x | sed s/GENRE=//g)

   ALB=$(metaflac --show-vc-field=ALBUM $x | sed s/ALBUM=//g)

   ART=$(metaflac --show-vc-field=ARTIST $x | sed s/ARTIST=//g)

   YE=$(metaflac --show-vc-field=YEAR $x | sed s/YEAR=//g)

   TRA=$(metaflac --show-vc-field=TRACKNUMBER $x | sed s/TRACKNUMBER=//g)

   FIL=$(echo $x | sed s/flac/ogg/g)

   flac -d $x -o - | oggenc -q $QUALITY -N "$TRA" -t "$TIT" -l "$ALB" \

        -a "$ART" -d "$Y" -G "$GEN" -o "$FIL" -

done

```

For converting FLAC files to mp3 using lame

```
#!/bin/bash

# /usr/local/bin/flac2mp3

# this script converts given flac files to mp3 files

BITRATE=256 # change if you want to

for x in $* ;

do TIT=$(metaflac --show-vc-field=TITLE $x | sed s/TITLE=//g)

   GEN=$(metaflac --show-vc-field=GENRE $x | sed s/GENRE=//g)

   ALB=$(metaflac --show-vc-field=ALBUM $x | sed s/ALBUM=//g)

   ART=$(metaflac --show-vc-field=ARTIST $x | sed s/ARTIST=//g)

   YE=$(metaflac --show-vc-field=YEAR $x | sed s/YEAR=//g)

   TRA=$(metaflac --show-vc-field=TRACKNUMBER $x | sed s/TRACKNUMBER=//g)

   FIL=$(echo $x | sed s/flac/mp3/g)

   flac -d $x -o - | lame -b $BITRATE --tn "$TRA" --tt "$TIT" --tl "$ALB" \

        --ta "$ART" --ty "$Y" --tg "$GEN" - "$FIL"

done
```

Didn't test them well, I'm sure they're expandable, but should work.

----------

## llsardonicll

I can go to audiocd:/FLAC and it will let me do FLAC files...been doing it all day... unless I'm interpreting

 that the wrong way.

----------

## supermihi

?? Which KDE version do you use? Did you install some special package?

----------

## llsardonicll

Using kde-3.4 monolithic here. Haven't installed any special package that I'm aware of, just a flac use flag.

*just checked and kaudiocreator will do flac...and some odd reason i have sound juicer installed

and it will do flac too.

----------

## supermihi

You're right, kaudiocreator seems to support FLAC quite well. I'll edit the HOWTO a bit.

----------

## tkdfighter

supermihi, I edited you script a bit. Now it's recursive and puts the mp3s in a destination directory:

```
#!/bin/bash

# /usr/local/bin/flac2mp3

# this script converts given flac files to mp3 files

LAMEOPTS="-h -p -m j -b 160";

FLACOPTS="-o";

LAME="/usr/bin/lame";

FLAC="/usr/bin/flac";

METAFLAC="/usr/bin/metaflac";

DIR=$1;

DESTINATION=$2;

if [[ $DIR == "-h" || $DIR == "--help" ]]

then

  printf "Usage: $0 [source directory] [destination directory]\n";

  printf "flac2mp3 converts flac files to mp3 files, while preserving the directory structure.\n";

  printf "\n";

  printf "options:\n";

  printf "\t-h, --help\t\tPrint this help list\n";

  printf "\n";

  exit 1;

fi

chars=$(echo $DIR | wc --chars);

#for y in $(find -print | grep -v .flac);

#for y in $(find $DIR -print | grep -v .flac | sed s/$DIR/./g);

for y in $(find $DIR -print | grep -v .flac);

do

  y=$(echo ${y:$chars});

  mkdir -p $DESTINATION/$y

done

for x in $(find $DIR -name *.flac) ;

do

  TIT=$($METAFLAC --show-tag=TITLE $x | sed s/TITLE=//g)

  GEN=$($METAFLAC --show-tag=GENRE $x | sed s/GENRE=//g)

  ALB=$($METAFLAC --show-tag=ALBUM $x | sed s/ALBUM=//g)

  ART=$($METAFLAC --show-tag=ARTIST $x | sed s/ARTIST=//g)

  YER=$($METAFLAC --show-tag=YEAR $x | sed s/YEAR=//g)

  TRA=$($METAFLAC --show-tag=TRACKNUMBER $x | sed s/TRACKNUMBER=//g)

  #FIL=$(echo $x | sed -e s/$DIR.//1 -e s/flac/mp3/g)

  FIL=$(echo ${x:$chars} | sed s/\.flac/.mp3/g);

  $FLAC -d $x $FLACOPTS - | $LAME $LAMEOPTS --tn "$TRA" --tt "$TIT" --tl "$ALB" \

   --ta "$ART" --ty "$YER" --tg "$GEN" - "$DESTINATION/$FIL";

done
```

edit: updated the script and added command line argumentsLast edited by tkdfighter on Fri Dec 09, 2005 6:18 pm; edited 1 time in total

----------

## ikke

You could just use abcde too  :Wink: 

----------

## tkdfighter

 *freshmeat.net/projects/abcde wrote:*   

> About:
> 
> abcde is a frontend to cdparanoia, wget, cd-discid, id3, and your favorite Ogg Vorbis (the default), MP3, FLAC, Ogg Speex, or MPP (Musepack) encoder. It grabs an entire CD and converts each track to the desired format, then comments or ID3-tags each file, all with one command. It supports multiple output in a single CD read, the creation of a single track from a CD, resume operation, CD concatenation, volume normalization, gapless encoding (with LAME), parallelization, SMP, proxies, customizable filename organization and munging, playlist generation, distributed encoding via distmp3, and more.

 

That's not what I need. I already use grip for that. What I needed was a program/script that would convert the flac files to mp3/ogg/whatever.  :Wink: 

----------

## bludger

I have a number of flac files that were ripped and encoded without tags.  Is it possible to use the flac files to do a cddb lookup and then insert this information in the flac files in some way other than burning a cd from the flac files?

----------

## supermihi

You could try musicbrainz, although I don't know if it works with flac's, maybe only MP3 is supported now.

----------

## ahubu

Thank you very much, great HOWTO. Often I really dread finding out the proper commandline options (and building it up from scratch), it's always good to have a working baseline (although in this case, I didn't change anything  :Smile: ). Happily FLACripping away here... some cd's just don't deserve t be mp3-ized.

----------

## ecatmur

 *bludger wrote:*   

> I have a number of flac files that were ripped and encoded without tags.  Is it possible to use the flac files to do a cddb lookup and then insert this information in the flac files in some way other than burning a cd from the flac files?

 You need a tagging program that supports FLAC. I use cowbell - it has a sane interface, automatic song lookup (from filename or other info), album cover support, and an automatic command line batch tagging interface.

----------

## ecatmur

I'd recommend sound-juicer over flac; the interface is a lot cleaner and it tags files properly in the default configuration.

----------

## Hauser

 *tkdfighter wrote:*   

> ... What I needed was a program/script that would convert the flac files to mp3/ogg/whatever. 

 

Try this:

```
$ mplayer -ao pcm -aofile xxx.wav xxx.flac; normalize xxx.wav; oggenc xxx.wav xxx.ogg; rm -f xxx.wav
```

No tags though.

----------

## hhaamu

 *Hauser wrote:*   

> 
> 
> ```
> $ mplayer -ao pcm -aofile xxx.wav xxx.flac; normalize xxx.wav; oggenc xxx.wav xxx.ogg; rm -f xxx.wav
> ```
> ...

 

1) oggenc supports flac input natively (incl tags!), no need for mplayer to interfere.

2) normalizing audio data is evil and unneeded when you have the power of replaygain (and vorbis comments). emerge media-sound/vorbisgain and do vorbisgain -a album/*.ogg

It's another thing to configure your players to use the stored replaygain data. XMMS, BMP, and Rhythmbox can do it, at least.

----------

## psiox

Hopefully this will help some people.

I've been doing the FLAC thing for a while myself, and as I have a car mp3 player that doesn't do anything but mp3s and an ipod that does mp3s/aacs, I try to maintain an automatically-transcoded collection of mp3s and aacs from the FLAC source.  So I found this interesting perl script called flac2mp3 and hacked on it until it did aacs with proper tags as well.    If you want to make AACs like me, emerge faad2 and faac first, then you can run this script fine.  Otherwise, you just need lame.

http://veritox.net/flac2aacmp3.tbz

Just run it like so:

./flac2aac.pl /path/to/FLAC/root /path/to/transcodes/root

(or flac2mp3.pl)

It'll ignore anything other than FLACs (and will ignore FLACs it has already transcoded, so it's safe to run a cronjob nightly and it will just do new stuff) and will construct the same relative paths in the transcode directory.  Enjoy, and I hope it helps someone!

----------

## ruizs

The flac2aac script is great, and was just what I was looking for.  I'm in a similar situation, with a need for different copies of my flac music.

I did edit the script slightly, so it would tag the files with a track# and genre.  However, when I import the resulting m4a files into itunes, it doesn't seem to recognize the genre and track number tags...

In the script:

```
my $convert_command =

                "$flaccmd @flacargs \"$quotedsrc\""

              . "| $lamecmd @lameargs --artist \"$srcframes->{ARTIST}\" --title \"$srcframes->{TITLE}\" --album \"$srcframes->{ALBUM}\" --year \"$srcframes->{YEAR}\" --genre \"$srcframes->{GENRE}\" --track \"$srcframes->{TRACKNUMBER}\" -o \"$quoteddest\" -";
```

The command line it issues:

```
flac --decode --stdout --silent "Jets_To_Brazil/Perfecting_Loneliness/Further_North.flac"| faac -q 200 -w --artist "Jets To Brazil" --title "Further North" --album "Perfecting Loneliness" --year "2002" --genre "Indie" --track "09" -o "/home/stever/mp4/Jets_To_Brazil/Perfecting_Loneliness/Further_North.m4a" -
```

Has anybody gotten all the tags working, when going from faac -> itunes??

thanks!

----------

## roguetoad

I've seen a lot of buzz about replaygain and was wondering how to factor that into ripping cd's to flac format. 

Grip has a Calculate gain adjustment option you can click under ripper, but I don't know if it works for flac. 

Second, there seems to be a couple of gain adjustments that can be calculated: 1. for the entire album 2. per track

I guess I'm wondering without some universal normalization, how replaygain would work across an entire collection of albums if these are the only two ways it can calculate. 

Anybody got the skinny on how replay gain really works and better yet, how to add it into this howto for ripping to flac?

----------

## jkcunningham

Since this is in 'Tips and Tricks' I thought I'd add a comment on this part:

 *supermihi wrote:*   

> ****
> 
> 2. i suggest using cdda2wav instead of grip's standard ripper cdparanoia, since it is about six times faster (for me, at least, could be machine dependant). It's, in the cdrtools package (don't know why that), so
> 
> ```
> ...

 

The reason cdparanoia is slower is that it does extensive error correction. Unless you know that what you are ripping is guaranteed to be error free, you want this. I can't count how many times I've ripped wavs that play with tics and tracking errors that cdparanoia fixes in the mp3s. 

And the reason cdda2wav is in the cdrtools package is that the development is managed by the same guy (Jorg Schilling) who wrote cdrecord. It actually has a flag to use cdparanoia for its error correction (-parania).  If you don't use it, it runs faster but won't fix any errors. 

-jeff

----------

## bitnick

This works almost too well.  :Smile:  Great guide - thanks!

-- Arvid

----------

## Nate_S

 *roguetoad wrote:*   

> I've seen a lot of buzz about replaygain and was wondering how to factor that into ripping cd's to flac format. 
> 
> Grip has a Calculate gain adjustment option you can click under ripper, but I don't know if it works for flac. 
> 
> Second, there seems to be a couple of gain adjustments that can be calculated: 1. for the entire album 2. per track
> ...

 

Replay gain calculates the level of a track against a fixed decibel level, then stores the adjustment in the tags of the file.  Album mode calculates the adjustment for the album overall, so that quiet songs stay quiet relative to the others.  You can store a replaygain adjustment in flac tags as well as any other, the issue is finding a player that will recognize them and adjust accordingly.  I think Quod Libet will, and probably amarok too.  

-Nate

----------

