LDP/LDP/howto/docbook/MP3-CD-Burning.sgml

464 lines
22 KiB
Plaintext

<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
<article>
<artheader>
<title>Linux MP3 CD Burning mini-HOWTO</title>
<pubdate>2001-05-29</pubdate>
<author>
<firstname>Greg</firstname>
<surname>Wierzchowski</surname>
<affiliation>
<address><email>greg@draxen.org</email></address>
</affiliation>
</author>
<abstract>
<para>A complete recipe for creating audio and data CDs from MP3 files.</para>
</abstract>
<revhistory>
<revision>
<revnumber>1.11</revnumber>
<date>2004-08-21</date>
<authorinitials>GW</authorinitials>
<revremark>Fixed a typo.</revremark>
</revision>
<revision>
<revnumber>1.10</revnumber>
<date>2004-07-14</date>
<authorinitials>GW</authorinitials>
<revremark>Fixed revision numbering to be in sync with CVS.</revremark>
</revision>
<revision>
<revnumber>1.9</revnumber>
<date>2004-07-14</date>
<authorinitials>GW</authorinitials>
<revremark>Small updates, added new sub-section.</revremark>
</revision>
<revision>
<revnumber>1.8</revnumber>
<date>2003-09-12</date>
<authorinitials>GW</authorinitials>
<revremark>Cleanup, update, fixes and minor layout change.</revremark>
</revision>
<revision>
<revnumber>1.7</revnumber>
<date>2002-04-26</date>
<authorinitials>GW</authorinitials>
<revremark>Divided into two sections: existing material to section "audio", new section "data" on data
CDs. Misc. additions.</revremark>
</revision>
<revision>
<revnumber>1.5</revnumber>
<date>2001-11-19</date>
<authorinitials>GW</authorinitials>
<revremark>Fixed omission in Disc-At-Once burning section.</revremark>
</revision>
<revision>
<revnumber>1.4</revnumber>
<date>2001-11-17</date>
<authorinitials>GW</authorinitials>
<revremark>Added Disc-At-Once burning section.</revremark>
</revision>
<revision>
<revnumber>1.3</revnumber>
<date>2001-09-02</date>
<authorinitials>GW</authorinitials>
<revremark>Added another example of decoding MP3 files with lame.</revremark>
</revision>
<revision>
<revnumber>1.2</revnumber>
<date>2001-07-12</date>
<authorinitials>GW</authorinitials>
<revremark>Minor layout changes; Added Translations subsection into Credits.</revremark>
</revision>
<revision>
<revnumber>1.1</revnumber>
<date>2001-06-12</date>
<authorinitials>GW</authorinitials>
<revremark>Minor cleanup; Regexp fix for MP3 to WAV name conversion example.</revremark>
</revision>
<revision>
<revnumber>1.0</revnumber>
<date>2001-05-29</date>
<authorinitials>GW</authorinitials>
<revremark>Initial Release.</revremark>
</revision>
</revhistory>
<keywordset>
<keyword>
MP3
</keyword>
<keyword>
CD
</keyword>
<keyword>
audio
</keyword>
<keyword>
recording
</keyword>
<keyword>
burning
</keyword>
<keyword>
WAV
</keyword>
<keyword>
music
</keyword>
</keywordset>
</artheader>
<section id="intro"><title>Introduction</title>
<para>
This mini-HOWTO was created because of my experience with burning music CDs
and lack of some specific information about sound normalization on the
Internet. I usually burn music CDs as a mix - different songs from different
sources.Very often volume level between songs varies greatly. This is the
first obstacle. Second, many of the files on the Internet are not
CD-compatible (16 bit, stereo, 44.1 kHz) and have to be converted. There are
many programs to burn music CDs from MP3 files, and many of them do the
conversion transparently. But I haven't seen a single tool that also
normalizes the volume, so that's why I worked out my own CD-burning recipe.
</para>
<para>If you just want to make a CD filled with music, and not be bothered with all of the details, I have good news for you: Kees Cook (<email>kees@outflux.net</email>) put together a tool based on this HOWTO, which automates all of the tasks outlined here. His program can be obtained from <ulink url="http://outflux.net/unix/software/mp3cd/">http://outflux.net/unix/software/mp3cd/</ulink>. Thanks, Kees!
</para>
<para>
This HOWTO is just about one thing - putting MP3 music on a CD, so that you can
listen to it. For in-depth information about MP3 files, please look at <emphasis>The Linux MP3
HOWTO</emphasis> by Phil Kerr, located at <ulink
url="http://www.tldp.org/HOWTO/MP3-HOWTO.html">http://www.tldp.org/HOWTO/MP3-HOWTO.html</ulink>.
For information about CD creation in general as well as CD burners, refer to
<emphasis>CD-Writing-HOWTO</emphasis> by Winfried Trümper, available at <ulink
url="http://www.tldp.org/HOWTO/CD-Writing-HOWTO.html">http://www.tldp.org/HOWTO/CD-Writing-HOWTO.html</ulink>.
Also, look at the <emphasis>CD Burning Resources</emphasis> section for more information.
</para>
<para>
I'm assuming you wish to burn a CD with the collection of songs you obtained
from different sources, all varying quality, but you want to get the
best-sounding CD possible. This mini-HOWTO outlines the steps that may
help you.
</para>
<section id="copyright"><title>Copyright and License</title>
<para>This document is copyright 2001 by Greg Wierzchowski and is released under
the terms of the GNU Free Documentation License, which is hereby incorporated
by reference. Send feedback to
<ulink url="mailto:greg@draxen.org"><citetitle>greg@draxen.org</citetitle></ulink>.
</para>
</section>
</section>
<section id="audio"><title>Audio CDs</title>
<section id="prepare"><title>Preparing the Tracks</title>
<para>
<note><title>Note</title><para>All commands assume bash shell</para></note>
</para>
<section id="cleanup"><title>Filename Cleanup</title>
<orderedlist>
<listitem><para>Collect all MP3 files in one directory. </para></listitem>
<listitem><para>If any filenames contain spaces, first convert them to underscores: </para>
<programlisting>
for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done </programlisting>
<para>This first step is important because, even if unix itself allows spaces in filenames,
most programs get confused by them.</para>
</listitem>
<listitem><para>If your MP3 files came from DOS/Windows, they may have
uppercase extensions. You can convert whole names to lowercase or just
extensions. For everything lowercase do:</para>
<programlisting>
for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done </programlisting>
<para>to convert just extensions:</para>
<programlisting>
for i in *.MP3; do mv "$i" "`basename "$i" .MP3`.mp3"; done
</programlisting>
</listitem>
</orderedlist>
</section>
<section id="converting"><title>Conversion</title>
<para>The CD Audio specification requires wave files that are 16 bit, stereo, 44.1 kHz. MP3 files often have different parameters, but we need to convert them to WAV first, anyway.</para>
<para>We have several choices for the conversion process.</para>
<section id="mpg321"><title>mpg123 and mpg321</title>
<para>Originally, there was only <command>mpg123</command>. However, it uses a proprietary licensing, and now there's an open source replacement - <command>mpg321</command>. Both commands use the same syntax: </para>
<programlisting>
for i in *.mp3; do mpg321 -w `basename $i .mp3`.wav $i; done </programlisting>
<para>When decoding 22khz MP3 files the output of <command>mpg123</command> may be distorted. I don't know how well <command>mpg321</command> deals with this problem. If you're converting with <command>mpg123</command>, use:</para>
<programlisting>
for i in *.mp3; do mpg123 --rate 44100 --stereo --buffer 3072 --resync -w `basename $i .mp3`.wav $i; done
</programlisting>
<para><citetitle>Mpg123</citetitle> can be obtained from <ulink url="http://www.mpg123.de/">http://www.mpg123.de/</ulink>.</para>
<para><citetitle>Mpg321</citetitle> is available from <ulink url="http://mpg321.sourceforge.net/">http://mpg321.sourceforge.net/</ulink>.</para>
<para><emphasis>NOTE</emphasis> I noticed that with some MP3 files mpg123 output was distorted.
At first I thought that MP3's were bad, but then I checked with another
player and they sounded OK. So <command>mpg123</command> is not my converter of choice.
</para>
</section>
<section id="madplay"><title>MAD</title>
<para>Another MP3 player/decoder, and the one I prefer, is <command>madplay</command>. It's available from <ulink url="http://www.mars.org/home/rob/proj/mpeg/">http://www.mars.org/home/rob/proj/mpeg/</ulink>.
With <citetitle>madplayer</citetitle>, the command line is: </para>
<programlisting>
for i in *.mp3; do madplay -o `basename $i .mp3`.wav $i; done </programlisting>
<para>
Unfortunately, <command>madplay</command> also had problems with some of MP3 files I had. I don't think there's a problem with the decoder, but rather with it handling broken MP3 files.</para>
</section>
<section id="lame"><title>Lame</title>
<para>The <command>lame</command> encoder, which has a decoding mode, seems
to handle difficult cases very well (<command>lame</command> can be found at <ulink url="http://www.mp3dev.org/mp3/">http://www.mp3dev.org/mp3/</ulink>) :
</para>
<programlisting>
for i in *.mp3; do lame --decode $i `basename $i .mp3`.wav; done
</programlisting>
</section>
<section id="ogg"><title>OGG files</title>
<para>Well, this HOWTO is about MP3 files, but OGG standard is an alternative which many people prefer over MP3 because of the licensing. To deal wit OGG files, you need to use:</para>
<programlisting>
for i in *.ogg ; do ogg123 -d wav -f `basename $i .ogg`.wav $i; done
</programlisting>
</section>
<section id="mplayer"><title>Converting other formats</title>
<para>Nico Genimakis sent me an email about using <emphasis>mplayer</emphasis> to covert audio in many different formats to WAV with automatic resampling to 44100Hz. Mplayer is known to be able to read almost anything, and it can convert your .ogg, .mp3, .flac, .wma etc.</para>
<para>usage (in this example converting WMA files):</para>
<programlisting>
for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader $i; done
</programlisting>
</section>
</section>
<section id="notes"><title>Conversion Notes</title>
<para>
<emphasis>NOTE:</emphasis> The <command>`basename $i .mp3`.wav</command> command
replaces MP3 extensions with WAV. There are 101 ways to do that, here's
the alternative: <command>`echo "$1" | sed 's/\.mp3$/.wav/'`</command>
</para>
<para>After the conversion, run &quot;<command>file *.wav</command>&quot; and check the
output for any files that differ from 16 bit, stereo 44100 Hz.</para>
<para>If there are files with different characteristics, convert them to the
above specs. For example, to convert file track01.wav to obtain sample
rate 44.1 kHz, you could use: </para>
<programlisting>
sox track01.wav -r 44100 track01-new.wav resample
</programlisting>
<para>or, if the above introduces static when converting mono files:</para>
<programlisting>
sox track01.wav -r 44100 -c 2 track01-new.wav
</programlisting>
<para><citetitle>Sox</citetitle> is so popular, that it's probably installed
by default with any Linux distribution, and can be obtained from
<ulink url="http://www.spies.com/Sox/">http://www.spies.com/Sox/</ulink>.
However, the command-line options are somewhat cryptic for the casual
user (me). Look at
<ulink url="http://www.spies.com/Sox/sox.tips.html">http://www.spies.com/Sox/sox.tips.html</ulink>
for some tips on usage.
</para>
</section>
</section>
<section id="normalisation"><title>Normalisation</title>
<para>Normalisation is a process during which all the sound files are brought to the same relative loudness level. I use a program by Chris Vaill (<email>cvaill@cs.columbia.edu</email>), called
<command>normalize</command> - it can be obtained from
<ulink url="http://www.cs.columbia.edu/~cvaill/normalize/">http://www.cs.columbia.edu/~cvaill/normalize/</ulink>
</para>
<para>
I use the following syntax (-m is for mix mode, where all files should be as loud as possible):</para>
<programlisting>
normalize -m *.wav
</programlisting>
</section>
</section>
<section id="burning"><title>Burning Your CD</title>
<para>
There are many programs to create CDs from WAV files. I use <command>cdrecord</command> for
command-line burning and <command>XCDROAST</command> for gui. For <command>cdrecord</command>,
you have to know
what SCSI device your CD-writer is. If you're using ATAPI writer, with older kernel, use SCSI
emulation (kernel module ide-scsi). As of kernel 2.6, you can use ATAPI directly, without SCSI emulation, by prepending <emphasis>ATAPI:</emphasis> to the device specification. Let's assume, that your ATAPI cdwriter
is on the second IDE bus as a master. Thus, it will have <filename>/dev/hdc</filename> device
file. To instruct the kernel that you want to treat it as a SCSI device, add
the following line to <filename>/etc/lilo.conf</filename>: </para>
<programlisting>
append=" hdc=ide-scsi"
</programlisting>
<para>
Also, if your kernel doesn't automatically load ide-scsi module, add
<command>insmod ide-scsi</command> into your <filename>rc.local</filename>
(or equivalent) file. Once you have our CD-writer recognized as a
SCSI device, run <command>cdrecord --scanbus</command> to
find out what's the "dev" parameter to cdrecord. On my system, the
output looks like the following: </para>
<programlisting>
scsibus1:
1,0,0 100) 'IOMEGA ' 'ZIP 250 ' '51.G' Removable Disk
1,1,0 101) 'HP ' 'CD-Writer+ 7100 ' '3.01' Removable CD-ROM
</programlisting>
<para>
So, the <command>cdrecord</command> command line will contain <command>dev=1,1,0</command> to specify the
device. Here is the complete command on my system: </para>
<programlisting>
cdrecord dev=1,1,0 -eject speed=2 -pad -audio *.wav
</programlisting>
<para>
And, with kernel 2.6:</para>
<programlisting>
cdrecord dev=ATAPI:1,1,0 -eject speed=2 -pad -audio *.wav
</programlisting>
<note><title>NOTE</title><para> The -pad argument is neccessary,
because all audio tracks on the CD must be adjusted for the proper
data length, which is not always the case with mp3 files. </para>
<para>Another way, would be to convert WAV files with <command>sox</command> into CDR format before burning:</para>
<programlisting>
sox file.wav file.cdr
</programlisting></note>
</section>
<section id="dao-burning"><title>Burning a DAO CD</title>
<para>
DAO, Disc-At-Once, is as of now the only method for burning a CD without a 2-second pause between the tracks.
It's useful for burning party mixes. The program for burning CDs in DAO mode is <command>cdrdao</command>, available from SourceForge, <ulink url="http://sourceforge.net/projects/cdrdao/">http://sourceforge.net/projects/cdrdao/</ulink>.
</para><para>
The <command>cdrdao</command> program uses description files called <emphasis>TOC</emphasis> (Table Of Contents, of course). There are two ways to create such file. First is to use a shell script, distributed with <command>cdrdao</command> source (in <filename>contrib</filename> directory, called <command>generate_toc.sh</command>. It takes a list of <filename>.wav</filename> files as an argument and produces a <filename>cd.toc</filename> file. Second way is to simply create such file yourself in a text editor of your choice. Here is a self-explanatory example:</para>
<programlisting>
CD_DA
TRACK AUDIO
AUDIOFILE "mix-01.wav" 0
TRACK AUDIO
AUDIOFILE "mix-02.wav" 0
TRACK AUDIO
AUDIOFILE "mix-03.wav" 0
TRACK AUDIO
AUDIOFILE "mix-04.wav" 0
TRACK AUDIO
AUDIOFILE "mix-05.wav" 0
</programlisting>
<para>
The <emphasis>0</emphasis> (zero) after the wave filename means start from the beginning of the file. There can be a second number providing the length (time) of file to record. The <command>xcdroast</command> creates similar <emphasis>TOC</emphasis> files, there are also examples in <filename>testtocs</filename> directory of <command>cdrdao</command> source.
</para>
<para>
The <command>cdrdao</command> by default uses the device <filename>/dev/cdrecorder</filename>, which should be a link to the cdwriter device. Assuming your cd recorder device file is <filename>/dev/scd0</filename>, create the link (as root) as follows:
</para>
<programlisting>
ln -s /dev/scd0 /dev/cdrecorder
</programlisting>
<para>
Then, assuming that the <emphasis>TOC</emphasis> file is named <filename>cd.toc</filename> the command to burn the cd is simply:
</para>
<programlisting>
cdrdao write cd.toc
</programlisting>
</section>
<section id="software"><title>Software</title>
<para>
There are some programs available, that can automate the process of creating CDs from MP3 files. Here is
arbitrarily selected list:</para>
<itemizedlist>
<listitem>
<para>
<emphasis>burnmp3</emphasis> - Program to automate burning with DAO method. <ulink
url="http://richardsnow.bizland.com/burnmp3/">http://richardsnow.bizland.com/burnmp3/</ulink>. </para>
</listitem>
<listitem><para>
<emphasis>mp32dao</emphasis> - a script from <emphasis>cdrdao</emphasis> distribution, in the
<emphasis>contrib</emphasis> directory. <ulink
url="http://cdrdao.sourceforge.net/">http://cdrdao.sourceforge.net/</ulink>.</para>
</listitem>
</itemizedlist>
</section>
<section id="data"><title>Data CDs</title>
<para>
<note><title>Note</title><para>This section is a work in progress, you're looking at initial, very sparse version.</para></note>
</para>
<para>
With increasing popularity of CD/MP3 players burning data CDs for listening purposes become practical. The advantage is definitely being able to squeeze ten times more music onto one CD (a very approximate figure).</para>
<para>
First I would recommend the filename cleanup steps outlined at the beginning of this document. Conversion to WAV is, obviously, not needed here. To normalize MP3 files without losing quality by conversions, use <command>mp3gain</command>. This program is available from <ulink url="http://www.maazl.de/project/mp3/mp3gain.html">http://www.maazl.de/project/mp3/mp3gain.html</ulink> or <ulink url="http://mp3gain.sourceforge.net/">http://mp3gain.sourceforge.net/</ulink> (but this second site seems to contain Windows-oriented version). You'd need to issue the command:</para>
<programlisting>
mp3gain -r -c *.mp3
</programlisting>
<para>
As far as burning is concerned, MP3 data CD-s are just a standard data CD's (ISO9660) with MP3 files on it. All MP3-CD players I know accept CD-s with directories in them, and I usually burn CD with Joliet extension and they work just fine. So to burn such a CD under linux, you first need to create an ISO image an then burn it on the CD as in the example below:
</para>
<programlisting>
mkisofs -J -o /tmp/mymp3s.iso /home/greg/mp3s/
cdrecord dev=1,0,0 speed=16 -eject /tmp/mymp3s.iso
</programlisting>
<para>
That's it!
</para>
</section>
<section id="resources"><title>CD Burning Resources</title><para>
<itemizedlist>
<listitem>
<para>Burning CDs on Linux: <ulink url="http://www-106.ibm.com/developerworks/linux/library/l-cdburn.html">http://www-106.ibm.com/developerworks/linux/library/l-cdburn.html</ulink></para>
</listitem>
<listitem>
<para>CD Burning from the command line: <ulink url="http://freeunix.dyndns.org:8088/site2/howto/Burn_em_Baby.shtml">http://freeunix.dyndns.org:8088/site2/howto/Burn_em_Baby.shtml</ulink></para>
</listitem>
<listitem>
<para>Comprehensive Burning Tutorial: <ulink url="http://www.yolinux.com/TUTORIALS/LinuxTutorialCDBurn.html">http://www.yolinux.com/TUTORIALS/LinuxTutorialCDBurn.html</ulink></para>
</listitem>
<listitem>
<para>CD Mastering Guide: <ulink url="http://debianlinux.net/~jama/howto/cd_mastering_steps.html">http://debianlinux.net/~jama/howto/cd_mastering_steps.html</ulink></para>
</listitem>
</itemizedlist>
</para>
</section>
<section id="credits"><title>Credits</title>
<para>
Special thanks to all the people who contribute to the Linux community and who made this HOWTO possible.
</para>
<section id="translations"><title>Translations</title>
<itemizedlist>
<listitem>
<para>
Im Eunjea - Translated this document to Korean, URL is <ulink url="http://kltp.kldp.org/eunjea/mp3_burning/">http://kltp.kldp.org/eunjea/mp3_burning/</ulink>.
</para>
</listitem>
<listitem>
<para>
Mendel L Chan - Translated this document to Chinese, URL is <ulink url="http://www.linux.org.tw/CLDP/mini/MP3-CD-Burning/">http://www.linux.org.tw/CLDP/mini/MP3-CD-Burning/</ulink>.
</para>
</listitem>
<listitem>
<para>
Chie Nakatani - Translated this document to Japanese, URL is <ulink url="http://www.linux.or.jp/JF/JFdocs/MP3-CD-Burning/index.html">http://www.linux.or.jp/JF/JFdocs/MP3-CD-Burning/index.html</ulink>.
</para>
</listitem>
<listitem>
<para>
Laszlo Daczi - Translated this document to Hungarian, URL is <ulink url="http://tldp.fsf.hu/HOWTO/MP3-CD-Burning-hu/index.html">http://tldp.fsf.hu/HOWTO/MP3-CD-Burning-hu/index.html</ulink>.
</para>
</listitem>
<listitem>
<para>
Alix - Translated this document to French, available at French TLDP site <ulink url=" http://www.traduc.org"> http://www.traduc.org</ulink>.
</para>
</listitem>
</itemizedlist>
</section>
<section id="othercredits"><title>Other Credits</title>
<para>I have had a great response to the previous releases of this HOWTO. So many people contributed, that I decided to change this section slightly in order to list all of the names.
So, I'd like to thank:</para>
<para>Greg Ferguson, Rob Russell, Terry Davis, Chris Vaill, Jamie Kellogg, Tom Panning, Adam Buckley, Ilia Lobsanov, Giuseppe "Cowo" Corbelli, Florent Fievez, Piero Ottuzzi, Kees Cook, Andrew Newman, David DeVault, Nico Genimakis, Jan-Erik Stromquist.
</para>
<para>And, most of all, I'd like to thank my lovely wife, Marta, for her love, support and understanding</para>
</section>
</section>
</article>