abcde: Command Line Music CD Ripping for Linux
I have tried a variety of programs to rip my personal collection of music from CD to computer. I found significant shortcomings with many of the GUI programs and throughout I was also a little nonplussed at the complexities of whole process. Fortunately I came across the program abcde which eliminates the needless froth of the GUI as well as seamlessly takes care of much of the complexity of the process. This small guide aims to demonstrate to Linux users how to harness this amazing script for their own purposes. I will describe on this page how to rip and encode music cds to each of the three major music formats: mp3, Ogg Vorbis and flac and to top it all off show how with a single command a music cd can be encoded to all three at the same time. How cool is that! But first for some preliminary setup:
Setting it all up ...
abcde is actually a long script that manipulates a handful of programs. To get started you will need to either download these programs from your distro's repository or compile from source. Details of these programs are:
- abcde
- "A Better CD Encoder" = abcde! Ordinarily, the process of grabbing the data off a CD and encoding it, then tagging or commenting it, is very involved. The abcde script is designed to automate this.
- cd-discid
- In order to do CDDB (Compact Disc Database) queries over the Internet, you must know the DiscID of the CD you are querying. cd-discid provides you with that information. It outputs the discid, the number of tracks, the frame offset of all of the tracks, and the total length of the CD in seconds, on one line in a space-delimited format.
- cdparanoia
- cdparanoia retrieves audio tracks from CDROM drives. The data can be saved to a file or directed to standard output in WAV, AIFF, AIFF-C or raw format. For the purposes of conversion to mp3 abcde directs cdparanoia to produce WAV files.
- easytag
- While it is true that overuse of gui programs will make you go blind I will admit to using this excellent tagging program to sometimes "clean up" after abcde. id3v2, vorbiscomment and metaflac will do the same but EasyTAG does it so much quicker! Don't overuse it, you will go blind!
- flac / flac 123 / metaflac
- This is the neat package of programs for working with the flac format. flac is a command-line tool for encoding, decoding, testing and analysing FLAC streams. flac123 is a no-frills command-line player for the FLAC format, very handy for testing the files. metaflac is used by abcde to add metadata to the flac files.
- id3 / id3v2
- id3 is an ID3 v1.1 tag editor while id3v2 is an ID3 v2 tag editor. ID3 tags are traditionally put at the end of compressed streamed audio files to denote information about the audio contents.
- lame / mpg321
- LAME is a program which can be used to create MPEG Audio Layer III (MP3) files. mpg321, or mpg123 which has risen phoenix-like from the ashes, is a small command line utility for testing the mp3s.
- oggenc / ogg123 / vorbiscomment
- oggenc is the encoder for Ogg Vorbis files that will also write the comments at encoding time. ogg123 is a beautifully compact player and vorbiscomment is a utility to edit Ogg Vorbis comments. These will usually be packaged as "vorbis-tools".
That is it for definitions. There is a wealth of details in the man pages for all these programs which I encourage you to consult. But now on to the nuts and bolts of the program:
Menus for abcde
abcde looks for two files on startup: /etc/abcde.conf and ~/.abcde.conf. The file abcde.conf is a fully commented configuration file that is well worth looking at, if only to copy to your home directory as ~/.abcde.conf (as is most usually done). But my gift to you, Gentle Reader, is a set of~/.abcde.conf files that will work "straight out of the box":
- ~/.abcde.conf for mp3
- ~/.abcde.conf for Ogg Vorbis
- ~/.abcde.conf for flac
- ~/.abcde.conf for mp3 + Ogg Vorbis + flac
Feel free to use these and call them your own, although I would encourage you to work on them a little and tweak them to match your own needs. For example in my own case I do not put spaces in filenames as this makes file manipulation under Linux a pain, I only use Ogg Vorbis and I only use album name and track number for tagging. I have omitted Ogg/Speex and MPP/MP+(Musepack), my encoding options are very conservative and I have omitted "normalising". So really I have provided a starting point only, feel free to develop and explore from here!
~/.abcde.conf for mp3
Who can escape mp3? I have placed this menu at the top of the list as I realise most people have mp3 players these days and many equate encoding with mp3. Bear in mind that it is a proprietary format and there are equally good formats that are totally free.
# Name of the encoder?
MP3ENCODERSYNTAX=lame
# What program to rip the tracks from CD?
CDROMREADERSYNTAX=cdparanoia
# Where is the encoding program?
LAME=lame
# Where are the tagging / commenting programs?
ID3=id3
ID3V2=id3v2
# Where are the other programs?
CDPARANOIA=cdparanoia
CDDISCID=cd-discid
# What options should be used for encoding?
LAMEOPTS='--preset standard'
OUTPUTTYPE="mp3"
# Where do the encoded tracks go to?
OUTPUTDIR="$HOME/music/"
# How do you want the tagging done?
OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
# Put spaces in the filenames.
mungefilename ()
{
echo "$@" | sed s,:,-,g | tr / _ | tr -d \'\"\?\[:cntrl:\]
}
# What extra options?
PADTRACKS=y # Makes tracks 01 02 not 1 2
EXTRAVERBOSE=y # Useful for debugging
EJECTCD=y # Please eject cd when finished :-)
The most obvious are to change is --preset standard but you will find that this deliver perfectly acceptable sound on most systems.
~/.abcde.conf for Ogg Vorbis
This is the format that I use myself and I bought an iRiver X20 player specifically for its native support of the amazing Ogg Vorbis format. Arguably produces better sound than mp3 and it is completely free.
# Name of the encoder?
OGGENCODERSYNTAX=oggenc
# What program to rip the tracks from CD?
CDROMREADERSYNTAX=cdparanoia
# Where is the encoding program?
OGGENC=oggenc
# Where is the tagging / commenting program?
VORBISCOMMENT=vorbiscomment
# Where are the other programs?
CDPARANOIA=cdparanoia
CDDISCID=cd-discid
# What options should be used for encoding?
OGGENCOPTS='-q 6'
OUTPUTTYPE="ogg"
# Where do the encoded tracks go to?
OUTPUTDIR="$HOME/music/"
# How do you want the tagging done?
OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
# Put spaces in the filenames.
mungefilename ()
{
echo "$@" | sed s,:,-,g | tr / _ | tr -d \'\"\?\[:cntrl:\]
}
# What extra options?
PADTRACKS=y # Makes tracks 01 02 not 1 2
EXTRAVERBOSE=y # Useful for debugging
EJECTCD=y # Please eject cd when finished :-)
Again the first are for change would be the -q 6 setting but I believe that most will be happy with the sound produced at this level.
~/.abcde.conf for flac
flac stands for Free Lossless Audio Codec and it is the only codec used here that does not remove material from the audio stream. I have not used it extensively myself as the trade off is large file size, but the sound quality cannot be matched by mp3 or ogg regardless of quality settings.
# Name of the encoder?
FLACENCODERSYNTAX=flac
# What program to rip the tracks from CD?
CDROMREADERSYNTAX=cdparanoia
# Where is the encoding program?
FLAC=flac
# Where is the tagging / commenting programs
METAFLAC=metaflac
# Where are the other programs?
CDPARANOIA=cdparanoia
CDDISCID=cd-discid
# What options should be used for encoding?
FLACOPTS='--best'
OUTPUTTYPE="flac"
# Where do the encoded tracks go to?
OUTPUTDIR="$HOME/music/"
# How do you want the tagging done?
OUTPUTFORMAT='${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
# Put spaces in the filenames.
mungefilename ()
{
echo "$@" | sed s,:,-,g | tr / _ | tr -d \'\"\?\[:cntrl:\]
}
# What extra options?
PADTRACKS=y # Makes tracks 01 02 not 1 2
EXTRAVERBOSE=y # Useful for debugging
EJECTCD=y # Please eject cd when finished :-)
The warning remains: flac files sound good but they are big. For a sound comparison though have a look at the next menu.
~/.abcde.conf for mp3 + Ogg Vorbis + flac
This one is the grandaddy of the all and is an incredible demonstration of the power of abcde. With this ~./abcde.conf file a music cd is ripped and encoded to all three formats at the same time and the resulting albums sorted into three different subdirectories. If you don't think that is cool I will reach through your computer monitor and poke you in the eye!
# What are the names of the encoding programs?
OGGENCODERSYNTAX=oggenc # Specify encoder for ogg
MP3ENCODERSYNTAX=lame # Specify encoder for mp3
FLACENCODERSYNTAX=flac # Specify encoder for flac
# What program to rip the tracks from CD?
CDROMREADERSYNTAX=cdparanoia # CD reader program to use
# Where are the encoding programs?
OGGENC=oggenc # Path to ogg encoder
LAME=lame # Path to lame encoder
FLAC=flac # Path to flac encoder
# Where are the tagging / commenting programs?
ID3=id3 # Path to id3 editor
ID3V2=id3v2 # Path to id3v2 editor
VORBISCOMMENT=vorbiscomment # Path to vorbiscomment
METAFLAC=metaflac # Path to metaflac
# Where are the other programs?
CDPARANOIA=cdparanoia # Path to cdparanoia
CDDISCID=cd-discid # Path to cd-discid
# What options should be used for encoding?
OGGENCOPTS='-q 6' # Options for ogg
LAMEOPTS='--preset standard' # Options for mp3
FLACOPTS='--best' # Options for flac
OUTPUTTYPE="ogg,mp3,flac" # mp3 +/- ogg +/- flac
# Where do the encoded tracks go to?
OUTPUTDIR="$HOME/music/" # Base directory for the music
# This divides the music into 3 folders:
# mp3 goes to $HOME/music/mp3/
# ogg goes to $HOME/music/ogg/
# flac goes to $HOME/music/flac/
OUTPUTFORMAT='${OUTPUT}/${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
# Put spaces in the filenames.
mungefilename ()
{
echo "$@" | sed s,:,-,g | tr / _ | tr -d \'\"\?\[:cntrl:\]
}
# What extra options?
PADTRACKS=y # Makes tracks 01 02 not 1 2
EXTRAVERBOSE=y # Useful for debugging
EJECTCD=y # Please eject cd when finished :-)
The part of the script that steers this is the simple ${OUTPUT} part. Run the script and have a listen to all three formats: a fascinating exercise!
Now for the main event!
So you have chosen your preferred format and placed the appropriate ~/.abcde.conf file? You are now ready to set the script in motion with the following complex command:
$ abcde
Just a little geek joke which, like Dad jokes, is not all that funny I guess. The abcde script will then process your ~/.abcde.conf file and generate a directory of neatly tagged files in the format of your choice. From here may I suggest that you read the man pages for all the individual programs invoked by this script and make whatever alterations are suitable to fit your particular needs. And remember "Have fun!".
And in conclusion ...
Of all the pages that I have written for Linux this one has been the most fun. I guess because abcde is such a beautifully written script that manipulates programs that are all gems in their own right. But more importantly I am having a great and productive time in the world of Linux and I feel as if I have joined a community and am contributing to it. What about you?