Saturday, June 9, 2007

MP3 encoding primer

Summary: A mini-tutorial on audio ripping and MP3 creation.

If you are trying to figure out how to make the best sounding MP3s from your favorite CD collection or keep wondering why certain MP3s sound better than others, here is some information that can help you sort things out.

First, a bit of background on CD ripping for MP3 novices (if you're not a novice, feel free to skip the next section).

Music (and other audio) on traditional CDs comes in uncompressed format. To copy a song from a CD you first need to rip it using a CD ripper software (no, you cannot just copy it in Windows Explorer). If you want to keep an audio track in original (uncompressed) format (i.e. without loss of quality), you need to rip it to a WAVE (or WAV) file (like Track01.wav). Because WAVE files are very large, it is more practical to convert (encode) audio to compressed formats. Most CD rippers can convert (encode) audio files to compressed formats when ripping them from CDs. Alternatively, you can generate compressed audio files from the already ripped WAVE files. There are many types of audio compression formats, but the most popular is probably MP3. Audio files compressed using the MP3 algorithm (MP3 files) are typically more then 10 times smaller than the original WAVE files. You must be aware that MP3 files may lose audio quality.

The quality of MP3 audio largely depends on the choice of encoder and encoding algorithm settings used when the MP3 file was generated from an original audio source (such as a WAVE file). Because after creating an MP3 file you cannot improve its quality, be careful when selecting the encoder and encoding algorithm settings.

LAME is a popular encoder which makes good quality audio and is (or can be) used with a number of audio rippers. LAME -- and other MP3 encoders -- can generate MP3 files of different quality based on various settings used during encoding, the most important of which is probably bit rate.

Bit rate defines the number of bits (or kilobits) that can be used to encode one second of audio. A higher bit rate normally produces better quality audio, but it also results in a larger file size. Most modern MP3 encoders can make very good quality audio at 128 kbps (kilobits per second) or higher; lower bit rates generally result in poor quality audio.

MP3 audio can be encoded using constant bit rate (CBR) or variable bit rate (VBR); the latter uses different bit rates for encoding different parts of the original audio with more complex parts encoded at higher bit rates and less complex parts encoded at lower bit rates. Using variable bit rate can help achieve better audio quality in smaller files (when compared to CBR). Some older MP3 players may not support VBR encoding, but they are quite rare.

To learn more about MP3 encoding, check the references at the end of this post, but if you just want to know how to make the best-sounding and reasonably-sized MP3 file, simply use a quality MP3 encoder and encode audio using a variable bit rate (VBR) with a minimum of 112 kbps (or higher). Many audio editors require users to install LAME binaries, but you can find a few, which already come with a built-in LAME encoder. For example, winLAME comes with pre-installed LAME binaries and also offers a simple user interface and easy-to-follow process.

If you are fond of a popular (and free) Audiograbber software, you need to manually change its MP3 encoding settings to use an external MP3 encoder, such as LAME (the default settings produce poor-quality 56-bit audio).

To install LAME, copy the LAME binaries from one of the distribution sources, such as RareWares, or following instructions at SourceForge); you can copy the files from the distribution bundle to a new Program Files folder (you will first need to create the folder, e.g. C:\Program Files\Lame).

After making sure that you have the LAME binaries, do the following:
  1. Start Audiograbber.

  2. Select the MP3 Settings option from the Settings menu.

  3. Check the External Encoder check box in the corresponding tab.

  4. Click the Browse button (located next to the text field displayed right below the External MP3 program name label) and select the LAME executable file (lame.exe) from the location where you copied the LAME distribution files.

  5. Change the Predefined arguments option to User Defined.

  6. Enter the following arguments in the Arguments field:

    -h -v -b 128 %s %d

    Some advanced users recommend more complex settings, such as:

    -V9 --vbr-new -q0 -mj -b32 -F --lowpass 19.7 --nspsytune --cwlimit 10.7 --athaa-sensitivity 1 %s %d
    or
    -V2 --vbr-new -q0 --lowpass 19.7 -b96 %s %d
    or
    -V2 --vbr-new -q0 --lowpass 19.7 --cwlimit 10.7 --scale 0.99 -b96 %s %d

    I haven't tried these, but if you experiment, you may be able to find the best sounding options that works for you.

  7. Click the OK button to save settings.

Now, when Audiograbber makes MP3 files, it will use the LAME encoder instead of its own.

To check the quality and encoding settings of an MP3 audio file, use the free EncSpot utility. It can guess which encoder was used to encode the file and give you a general idea of the audio quality of the file.

Here are some tools that can help you generate and improve your MP3s:
Audacity
Exact Audio Copy
mp3DirectCut
MP3Gain
Mp3Tag
MP3/Tag Studio
mpTrim
Monkey's Audio

Additional references:
First look: Digital Media Core, Audio Format: MP3
How MP3 Files Work
How to turn your MP3’s into ringtones for your mobile phone for free
Variable Bit Rate: Getting the best Bang for your Byte (read comments, they have a lot of good info)
Creating quality audio-files using Windows, L.A.M.E., Ogg Vorbis
Wait wait... fix this podcast

4 comments:

  1. MP3 encoding - it would really add charm to your post if you post how MP3 got its name. MP3 was one of the algorithms used to compress video files in the early days when Apple looked out for a suitable format for their Video files. MP3 is one of the algorithms (third one to be precise) proposed by the Germans. MP3 didn't work well as a video compression algorithm but it turned out to be a boon for the audio files. MP3 is a lossy compression algorithm.

    Anyway, I like your post.

    ReplyDelete
  2. Thanks chevalier. I intentionally did not want to include more info than most people would need to make the post shorter. There are some links to WIKI (and other) articles that should cover historical info for the interested. This is good info, though. Thanks again.

    ReplyDelete
  3. Hi Alex, Thanks for the info, I founded @ your website. I just needed info about Lame. :)

    ReplyDelete