Converting MP3 files - step by step tutorial
As some of you might know, Nightmedia has an extended collection
of CD's archived in best quality MP3 format. When you download casually
stuff from the internet, quality will probably mean nothing to you.
Learn here something different.
Our intent is to archive what we get our hands on in the best possible
quality. Best possible means here a lot of things. One can compress
music in a lossless format like monkey audio, but no portable player
will be able to play it. Also, you can do yourself the non-service
to compress music in a dead-end format like apple formats, realaudio,
etc.., or compress MP3 in 320 KB resolution, just to think that
you preserve some quality. The matter that all you do then is to
waste space, is not so obvious.
First of all: have the patience to read this page entirely. It
contains important information, and will help you set your system
up correctly.
if you just need a script to re-convert your mp3's in a batch to
a lower resolution for your flash player, look at our
Perl script example below.
We tested a lot of solutions, programs, compressors, and we reached
the following base recipe:
- MP3 encoding in 256 KBit fix rate format, using
LAME
- Interface using Exact Audio Copy
The Encoder
LAME is pretty much the best MP3 encoder out there. You can find
a lot of reviews that will offer you enough data to support it.
Here is a message board where you will find a lot of information
about it: http://www.hydrogenaudio.org/
Since it is a free software, and it is easy to use it in a batch
mode, we also use it for re-conversion of the master format (256Kbit)
into smaller bitrates, i.e. 130KBit VBR. We will provide an example
of such a tool written in Perl, that uses Lame to (re)encode files.
Here is the link
to dowload the latest version of LAME
The Interface
Encoding MP3 formats from a CD requires a software that reads the
CD into a .wav format, then compresses the file using the encoder
above. A lot of encoders out there have problems reading data correctly
from the CD. Comparing a lot of tools, we decided for Exact Audio
Copy. This software is "cardware", read
more here about this licensing mode.
Here is
the link to the Exact Audio Copy home page
The Naming Convention
You want to have a very organized collection. The way we did it,
is save the CD's in a directory structure, first by author, then
by CD title. The track names begin with the track number, then a
space, then a dash, a space again, then the track title:
Artist Name/CD Name/01 - This Track Name.mp3
If the CD is a compilation, the artist will be set on "Various
Artists" unless it is a collection, like "The Rolling
Stones Collection" which then takes priority.
If the CD contains tracks by other artists, or is a compilation,
the track titles will be as follows:
Various Artists/CD Name/01 - This Artist - This Track Name.mp3
The encoding software will provide you with means to configure
this properly. If you want to later change the name of the file
or the ID3 tag contents, you can still use Perl to do it, using
the structure that you create in here.
Configuring Exact Audio Copy
We provide here a step by step install of the software, along with
some comments about the configuration particularities.
First of all, install Exact Audio Copy, using default values
for the install directories.
Download LAME, extract from the zip package and copy the
lame.exe in the directory where you installed the Exact Audio Copy.
Start Exact Audio Copy, select the correct CD drive from
the selector box:

Click on Eac / EAC options, or press F9
Configure the settings using the following screenshots. When choosing
directories, use a drive with enough space to hold your data:



Click on Eac / Drive options, or press F10
Click on "Detect Read Features" and let the system
examine your drive. If your CD does not support C2, go get yourself
a brand CD drive like Toshiba, Teac, Sony, or search the web for
one that does. You can also send the data about your CD drive to
the EAC database, in the screen following this one, it would help
other people configure their system faster. Your screen should look
something like:

Also click "Examine C2 Feature", and make sure
that way that C2 error detection functions properly. Use for that
a scratched CD, to speed up the detection process.
When you are done, the resulting drive options screen will look
as follows:

Please understand that reading CD data without these settings will
result in low quality encodings. Be serious about quality.
Click on Eac / Compression options, or press F11
Configure the options as in the following screenshots:


Click on Eac / freedb/Database options, or press F12
Configure the options as in the following screenshot, use your
email address:

Converting a CD to MP3
Now that the software is configured, you can start encoding MP3's.
A few things you have to keep in mind, are:
Always, always, always fill correctly to the best of your
knowledge the CD title, CD Artist, Release Year,
and of course Genre. If you encode a historical recording,
use the year of the recording of the master tape, and not the year
of the CD release.
If the freedb did not find your CD, enter the data manually,
by editing the track titles and the other fields. If you do not
have the CD cover, search online for that CD, and find the tracks
with the correct name. Please take your
time, and do the job completely and correctly. When you
will have thousands of CD's, you will realize how important it is,
to have the correct data at hand.
Here is an example, from a CD that was correctly identified by
freedb, with the correct year and genre:

Now, click on the MP3 button, and wait for the CD to be encoded.
The encoding process will involve starting a command interpreter
and run the lame.exe against the original wave track. On some systems
that would be slow, be patient. We know that there are MP3 encoders
out there that encode the track in one pass, but they are not delivering
quality!
At the end of the encoding, you will see the CRC proofs for every
track, which reassure you of the data integrity:

During your encoding, you might experience reading errors. Exact
Audio Copy does what no other programs do, it interpolates out of
a series of re-reads the best possible match, and offers you that
way the best result on very damaged CD's. Here is how it looks,
when errors are corrected:

Of course, the encoding will be very slow, since the software reads
repeatedly the data to estabilish the best match, please be patient.
Comments about the Various Artists option
If you want to have all the data in one place, you will have to
do your best to make it that way. Either use the checkbox "Various
Artists" or type it in in the CD title. Do not accept just
"Various", as some CD's are in the freedb database. Also,
when you encode such a CD, use the alternate naming convention:

After you convert the CD, you might realize that the artist name
is duplicated in the file name, that can happen. You can use then
some MP3 tag editor to correct the tags values, so the artist name
will be in the right tag.
If you have to enter the artist name manually, since it was not
correctly entered in the freedb database, make it look like in the
following screen. Exact Audio Copy offers
you the chance to separate the Artist Name from the Track Name with
a forward slash, look in the example below.
You have to understand that the freedb has a lot of good information,
but often it is erroneously entered. You can, and should edit the
entries manually.
The second phase, which is the command line encoding, will look
as follows:

Perl makes batch conversion a breeze
It is good to have the music in the best possible quality, but
most portable MP3 players have limited space. Also, on the road,
due to the surrounding noise, you can use a lower quality and still
be happy. You can use a perl script to go through your directory
structure, and re-convert the files to the resolution you want.
You will need Perl installed, and one module from CPAN: MP3::Info
Here is what I use to reconvert the archive files, into MP3's for
the road. Most of the times I am using the 130 KBit VBR encoding
scheme:
cd c:\media.convert\
c:\convert.pl . 130
Save the following script as c:\convert.pl
#!perl -w
use strict;
use vars qw($OS);
use Cwd;
use Config;
use MP3::Info;
unless($OS){unless($OS = $^O){$OS=$Config::Config{'osname'}}}
process(@ARGV);
sub process {
$|++;
my $Path = shift || die "No path provided";
my $Params = shift || '';
if ($Path eq '.') {
$Path = getcwd();
$Path =~ s/\/$//;
}
die "Invalid path provided: $Path" if ! -e $Path || ! -d $Path;
if (! $Params) {
print "You did not provide an encoding resolution.\n";
$Params = 130;
}
$Params = '--alt-preset '.$Params if $Params =~ /^\w+$/;
print qq~The files in $Path will be converted using $Params.
You have 5 seconds to stop this...\n~;
sleep 5;
$Params .= ' --add-id3v2' if $Params !~ /--add-id3v2/;
WorkDir($Path, $Params);
}
sub WorkDir {
my ($File);
my $Path = shift;
my $Params = shift;
opendir (DIR, $Path) or die "Can't open $Path:. ".$!;
my @Files = sort grep(!/^\.\.?$/, readdir(DIR));
closedir (DIR);
FILE: foreach $File(@Files) {
if (-d "$Path/$File") {WorkDir("$Path/$File", $Params); next FILE};
if ($File =~ /\.mp3$/oi) {
my $FullFile = "$Path/$File";
my $TempFile = "$Path/temp.mp3";
unlink($TempFile) if -e $TempFile;
EncodeFile($FullFile, $TempFile);
if (! -e $TempFile) {
print "Encode failed on: $TempFile\n";
}
else {
unlink($FullFile);
rename ($TempFile, $FullFile) || die "could not rename $TempFile to $FullFile";
print "Converted $FullFile\n";
}
}
elsif ($File =~ /(.+)\.wav$/oi) {
my $FullFile = "$Path/$1.mp3";
my $TempFile = "$Path/$File";
EncodeFile($TempFile, $FullFile);
if (! -e $FullFile) {
print "Encode failed on: $TempFile -> $FullFile\n";
}
else {
unlink $TempFile;
}
}
}
}
sub EncodeFile {
my ($x, $tag);
my $Source = shift;
my $Target = shift;
my $Params = shift;
my $DefaultTag = {
TITLE => '',
YEAR => '2004',
ARTIST => '',
ALBUM => '',
GENRE => 'Rock',
TRACKNUM => '',
COMMENT => '',
};
if ($Source =~ /([^\/]+)\/([^\/]+)\/(\d+)\s*-\s*([^\/]+)\.w+$/oi) {
$DefaultTag->{ARTIST} = $1;
$DefaultTag->{ALBUM} = $2;
$DefaultTag->{TRACKNUM} = $3;
$DefaultTag->{TITLE} = $4;
}
elsif ($Source =~ /Various Artists\/([^\/]+)\/(\d+)\s*(\.|-)\s*([^\/]+)\.w+$/oi) {
$DefaultTag->{ALBUM} = $1;
$DefaultTag->{TRACKNUM} = $2;
my $Title = $3;
$DefaultTag->{ARTIST} = 'Various Artists';
$DefaultTag->{TITLE} = $Title;
if ($Title =~ /([^.]+)\s+\.\s+(.+)/ ||
$Title =~ /([^\-]+)\s+-\s+(.+)/) {
$DefaultTag->{ARTIST} = $1;
$DefaultTag->{TITLE} = $2;
}
}
if ($Source =~ /\.wav$/oi) {
$tag = $DefaultTag;
}
else {
$tag = get_mp3tag($Source) || {};
}
my @MP3Params = qw(TITLE YEAR ARTIST ALBUM GENRE TRACKNUM COMMENT);
foreach $x(@MP3Params) {
$tag->{$x} = $DefaultTag->{$x} if ! exists $tag->{$x};
$tag->{$x} =~ s/\s+$//;
$tag->{$x} =~ s/^\s+//;
$tag->{$x} =~ s/\s+/ /;
$tag->{$x} =~ s/"/'/g;
}
$Params .= qq~ --tt "$tag->{'TITLE'}"~;
$Params .= qq~ --ty "$tag->{'YEAR'}"~;
$Params .= qq~ --ta "$tag->{'ARTIST'}"~;
$Params .= qq~ --tl "$tag->{'ALBUM'}"~;
$Params .= qq~ --tg "$tag->{'GENRE'}"~;
$Params .= qq~ --tn "$tag->{'TRACKNUM'}"~;
$Params .= qq~ --tc "$tag->{'COMMENT'}"~;
if ($OS =~ /win/i) {
$Source =~ s/\//\\/g;
$Target =~ s/\//\\/g;
}
`lame $Params "$Source" "$Target"`;
return;
}
Final comments
Please read this page multiple times. Make sure you understand
how things get configured. Email
me if you have questions.
|