May 15, 2006

CLI Magic: A better CD encoder

Author: Manolis Tzanidakis

User Level: Beginner to intermediate

A better CD encoder (abcde) is a console-based utility that grabs tracks off audio CDs and converts them to MP3, Ogg Vorbis, and other formats using backend programs such as cdparanoia and cdda2wav for grabbing tracks, and oggenc and lame for encoding them.

Abcde is actually just a Bourne shell script, albeit a fairly long one. It is well-written, and easy to hack and customize if you want to add features or change the way it works. Packages are available for most Linux distributions and BSDs, but if you can't find a suitable package for your favorite OS, don't worry; since it's a shell script, no compilation is required. Just download the latest tarball, unpack it, and run make install as root to install it on your system.

Since abcde is just a front end, you may need to install some other programs in order to get the job done, if they're not installed already. For ripping audio tracks from CDs, I'd suggest cdparanoia, because it has error-correction features in addition to its basic ability to read audio from CDs. The current stable version of abcde, 2.3.0, supports encoding to Ogg Vorbis, MP3, FLAC, Ogg Speex, and Musepack (MPP/MP+) digital formats. Install the necessary encoding tools according to the format you want to use.

I use oggenc from the vorbis-tools package for Ogg Vorbis and LAME for encoding MP3s. Other useful tools include Normalize (packaged as normalize-audio on Debian-based distributions), for adjusting the volume of the audio files to a standard level, and of course eject for ejecting a disc when done.

Configuration and usage

You can start using abcde right away by typing abcde without any other options. It will download track information -- artist and album names, along with the track list -- from Freedb.org. It will convert the tracks to Ogg Vorbis format and then clean up its temporary files. If you want to use another encoding format, use the -o option and one of the output types: ogg, mp3, flac, spx, or mpc. You can specify multiple output types by using a comma-separated list: -o ogg,mp3.

By default, abcde expects to find your CD-ROM device at /dev/cdrom. If you have symlinked your CD-ROM device name to something other than /dev/cdrom, or your system has more than one drive, you can define the drive that will be used with the -d option followed by the device node. For example, if your CD-ROM drive is /dev/scd0, you should use -d /dev/scd0. If you have the eject program installed on your system, you can use the -x option and have your disc ejected automatically when you're done ripping.

If your system is offline, or for some reason you don't want to download CDDB information off the Internet, you can pass the -n option to the program and skip that part. Whether you choose to use CDDB or not, abcde will ask if you want to manually edit the disc information, and if you say you do, it will load the default text editor (as set with the $EDITOR shell variable) for manual editing.

If you are lucky enough to have a system with multiple CPUs, you can use the -j option followed by the number of your CPUs to have more than one encoding process running simultaneously, saving you some time. Abcde supports distributed encoding to multiple computers by using distmp3, but I've never used it.

You might think that all these switches and options might be a bit difficult to remember every time you want to use the program -- and you're probably right. But you don't need to worry, because you can store all of your default options to a configuration file. The default system-wide configuration file for abcde is /etc/abcde.conf, or /etc/abcde/abcde.conf on Gentoo Linux, and users can have their own configuration files at $HOME/.abcde.conf. You can override the default name with -c filename.

Let's create a simple configuration file that will use /dev/scd0 as the CD-ROM device, encode to Ogg Vorbis with quality level 7, eject the disc when done, and output the final files to a directory named music on our home directory:

OUTPUTTYPE=ogg # encode tracks to the patent-free Ogg Vorbis format
OGGENCOPTS="-q 7" # encoding quality level for oggenc. Scale: -1 (lowest) - 10 (highest)
CDROM=/dev/scd0 # use /dev/scd0 as the reading device
OUTPUTDIR=~/music # place completed files in the music directory on my homedir
EJECTCD=y # eject the disc when done

If you don't like the way abcde names the completed files (Artist - Album/Track_Number - Track_Name), you can add something like the following lines in your configuration file:

OUTPUTFORMAT='${ARTISTFILE} - ${ALBUMFILE}/${TRACKNUM} - ${TRACKFILE}'
VAOUTPUTFORMAT='VA - ${ALBUMFILE}/${TRACKNUM} - ${TRACKFILE} [${ARTISTFILE}]'

The first line is for CDs by a single artist or music group. The second is for multi-artist CDs, such as collections or movie soundtracks. If your CD is multi-artist, you might find the normalization feature particularly useful, especially in the batch mode. It preserves relative volume differences between all the tracks of an album. To use normalization, run abcde with the -b option or add BATCH=y to your configuration file. We should note that abcde was developed mainly on Debian, and thus expects to find the normalize executable named as normalize-audio. If you don't use a Debian-based distribution, add NORMALIZE=normalize to your configuration file.

All available options are well documented in the software's man page, and an example configuration file is supplied with the program. Read those for further customization and more advanced usage.

Conclusion

Some of the most obvious benefits of console-based programs are faster loading times, smaller size, and fewer dependencies on external libraries. Console-based programs can also run and be managed remotely using SSH sessions and GNU Screen, eliminating the need for a keyboard and monitor connected locally. Of course, these things apply to abcde too -- after all it is "a better CD encoder."

Click Here!