Hasonlóan a hangforrásból való kódoláshoz, a CD-ről történő kódolás is kétlépcsős. Először a hangsávokat le kell szedni a CD-ről és WAV formátumban kell elmenteni. Aztán a WAV fájlt konvertáljuk tovább MP3-ba.
A MP3-kódoló programokat két nagy csoportra oszthatjuk, a konzolon futó és az X alatt futó programok csoporjára. Mindkét csoport ugyanazt a feladatot látja el, de az X alapúakat egyszerűbb használni (és jobban is néznek ki).
Ismét ellenőrizzük, hogy elegendő hely van-e a merevlemezen.
Írtam egy nagyon egyszerű Perl scriptet, ami leszedi és MP3-ba kódolja a CD sávjait.
#!/usr/bin/perl
if ($ARGV[0] ne "") {
$count = 1;
do {
$cdcap = system("cdparanoia", $count, "/mnt/mp3/cdda.wav");
$track = "$ARGV[1]/track".$count.".mp3";
$enc = system("bladeenc /mnt/mp3/cdda.wav $track -br 256000");
$count++;
}
until $count > $ARGV[0];
exit;
}
else {
print "Használat: cdriper [sávok száma] [célkönyvtár]\n\n";
}
Jegyezzük meg, hogy ez a script nagyon primitív, semmi sallangot (pl. hibaellenőrzés) nem tartalmaz. Akinek kedve van rá, továbbfejlesztheti :)
A legfontosabb sorok:
$cdcap = system("cdparanoia", $count, "/mnt/mp3/cdda.wav");
Ez a sor hívja meg a cdparanoia programot, ami a sávokat leszedi. A cdparanoia a nyers CD hangadatokat WAV formátumúvá alakítja.
Én Cdparanoia-t használtam, de ha a CDDA2WAV programot szeretnénk használni akkor a parancssor ez lenne:
$cdcap = system("cdda2wav", $count, "/mnt/mp3/cdda.wav");
A legfontosabb paraméterek a $count, amely a leszedendő sávok számát tartalmazza, és a keletkező WAV fájlok elérési útja. A példában ez a gyökérkönyvtár lesz az MP3 SCSI meghajtón.
Ezután a WAV fájlt MP3-ba kódoljuk a Bladeenc segítségével.
Ez a kis Perl script szükségtelenné teszi, hogy egyenként szedjük le és kódoljuk a sávokat, és szükségtelenné teszi a cdparanoia köteg üzemmódjának a használatát is. Ez lecsökkenti a szükséges üres lemezterületet, ugyanis a cdparanoia köteg üzemmódja az egész lemezt egyben leszedné, ami akár 600 MB is lehet.
Ha a Lame vagy Gogo programokat szeretnénk használni, cseréljük ki a kódolót megadó sort:
$enc = system("lame /mnt/mp3/cdda.wav $track -b 256");
$enc = system("gogo /mnt/mp3/cdda.wav $track -b 256");
A következőkben megadjuk minden MP3-kódoló lehetséges kapcsolóit.
Bladeenc
BladeEnc 0.91 (c) Tord Jansson Homepage: http://bladeenc.mp3.no
===============================================================================
BladeEnc is free software, distributed under the Lesser General Public License.
See the file COPYING, BladeEnc's homepage or www.fsf.org for more details.
Usage: bladeenc [global switches] input1 [output1 [switches]] input2 ...
General switches:
-[kbit], -br [kbit] Set MP3 bitrate. Default is 128 (64 for mono output).
-crc Include checksum data in MP3 file.
-delete, -del Delete sample after successful encoding.
-private, -p Set the private-flag in the output file.
-copyright, -c Set the copyright-flag in the output file.
-copy Clears the original-flag in the output file.
-mono, -dm Produce mono MP3 files by combining stereo channels.
-leftmono, -lm Produce mono MP3 files from left stereo channel only.
-rightmono, -rm Produce mono MP3 files from right stereo channel only.
-swap Swap left and right stereo channels.
-rawfreq=[freq] Specify frequency for RAW samples. Default is 44100.
-rawbits=[bits] Specify bits per channel for RAW samples. Default is 16.
-rawmono Specifies that RAW samples are in mono, not stereo.
-rawstereo Specifies that RAW samples are in stereo (default).
-rawsigned Specifies that RAW samples are signed (default).
-rawunsigned Specifies that RAW samples are unsigned.
-rawbyteorder=[order]Specifies byteorder for RAW samples, LITTLE or BIG.
-rawchannels=[1/2] Specifies number of channels for RAW samples. Does
the same as -rawmono and -rawstereo respectively.
Global only switches:
-quit, -q Quit without waiting for keypress when finished.
-outdir=[dir] Save MP3 files in specified directory.
-quiet Disable screen output.
-nocfg Don't take settings from the config-file.
-prio=[prio] Sets the task priority for BladeEnc. Valid settings are
HIGHEST, HIGHER, NORMAL, LOWER, LOWEST(default) and IDLE
-refresh=[rate] Refresh rate for progress indicator. 1=fastest, 2=def.
-progress=[0-8] Which progress indicator to use. 0=Off, 1=Default.
Input/output files can be replaced with STDIN and STDOUT respectively.
Lame
LAME version 3.50 (www.sulaco.org/mp3)
GPSYCHO: GPL psycho-acoustic model version 0.74.
USAGE : lame [options] <infile> [outfile]
<infile> and/or <outfile> can be "-", which means stdin/stdout.
OPTIONS :
-m mode (s)tereo, (j)oint, (f)orce or (m)ono (default j)
force = force ms_stereo on all frames. Faster and
uses special Mid & Side masking thresholds
-b <bitrate> set the bitrate, default 128kbps
(for VBR, this sets the allowed minimum bitrate)
-s sfreq sampling frequency of input file(kHz) - default 44.1
--resample sfreq sampling frequency of output file(kHz)- default=input sfreq
--mp3input input file is a MP3 file
--voice experimental voice mode
-v use variable bitrate (VBR)
-V n quality setting for VBR. default n=4
0=high quality,bigger files. 9=smaller files
-t disable Xing VBR informational tag
--nohist disable VBR histogram display
-h use (maybe) quality improvements
-f fast mode (low quality)
-k disable sfb=21 cutoff
-d allow channels to have different blocktypes
--athonly only use the ATH for masking
-r input is raw pcm
-x force byte-swapping of input
-a downmix from stereo to mono file for mono encoding
-e emp de-emphasis n/5/c (obsolete)
-p error protection. adds 16bit checksum to every frame
(the checksum is computed correctly)
-c mark as copyright
-o mark as non-original
-S don't print progress report, VBR histograms
Specifying any of the following options will add an ID3 tag
--tt <title> title of song (max 30 chars)
--ta <artist> artist who did the song (max 30 chars)
--tl <album> album where it came from (max 30 chars)
--ty <year> year in which the song/album was made (max 4 chars)
--tc <comment> additional info (max 30 chars)
MPEG1 samplerates(kHz): 32 44.1 48
bitrates(kbs): 32 48 56 64 80 96 112 128 160 192 224 256 320
MPEG2 samplerates(kHz): 16 22.05 24
bitrates(kbs): 8 16 24 32 40 48 56 64 80 96 112 128 144 160
Gogo
GOGO-no-coda ver. 2.24 (Feb 12 2000)
Copyright (C) 1999 PEN@MarineCat and shigeo
Special thanks to Keiichi SAKAI, URURI, Noisyu and Kei
This is based on LAME3.29beta and distributed under the LGPL
usage
gogo inputPCM [outputPCM] [options]
inputPCM is input wav file
if input.wav is `stdin' then stdin-mode
outputPCM is output mp3 file (omissible)
options
-b kbps bitrate [kpbs]
-br bps bitrate [ bps]
-silent dont' print progress report
-off {3dn,mmx,kni(sse),e3dn}
-v {0,..,9} VBR [0:high quality 9:high compression]
You should combine this with -b option
for only RAW-PCM input
-offset bytes skip header size
-8bit 8bit-PCM [dflt 16bit-PCM]
-mono mono-PCM [dflt stereo-PCM]
-bswap low, high byte swapping for 16bitPCM
-s kHz freq of PCM [dflt 44.1kHz]
-nopsy disable psycho-acoustics
-m {s,m,j} output format s:stereo, m:mono, j:j-stereo
-d kHz change sampling-rate of output MP3
-emh {n,c,5} de-emphasis
-lpf {on,off} 16kHz filter [dflt use if <= 128kbps; not use if >= 160kbps]
-test benchmark mode
-delete delete input file, after encoding
A grafikus felhasználói felülettel rendelkező MP3-kódolók rendelkeznek a konzol alapú programok minden funkciójával, de egy szép és könnyen kezelhető felületet is nyújtanak. A Grip és a RipperX hasonlóan működnek, mindkettőben kijelölhetünk konvertálásra egy, több vagy akár az összes hangsávot egy CD-ről. Mindkettő támogatja a CDDB adatbázist, amely letölti egy szerverről az album nevét és a számcímeket, megkímélve ezzel minket a begépeléstől.
A kódolókról szóló fejezetben három különböző programot említettem: bladeenc, lame és gogo. A fő különbség a kódolási teljesítményben van (bár vannak különbségek a választható kapcsolók között is, ahogy ezt korábban láthattuk).
Lássunk egy rövid példát. Leszedtem egy hangsávot egy CD-ről, és különböző kódolókkal MP3 formátumra alakítottam. A kódolók azonos paraméterekkel futottak azonos rendszeren.
[dj@megajukebox]$ ls -l cdda.wav
-rw-rw-r-- 1 dj dj 59823164 Feb 10 00:56 cdda.wav
[dj@megajukebox]$ bladeenc cdda.wav -br 256
BladeEnc 0.91 (c) Tord Jansson Homepage: http://bladeenc.mp3.no
===============================================================================
BladeEnc is free software, distributed under the Lesser General Public License.
See the file COPYING, BladeEnc's homepage or www.fsf.org for more details.
Files to encode: 1
Encoding: ../test.wav
Input: 44.1 kHz, 16 bit, stereo.
Output: 128 kBit, stereo.
Completed. Encoding time: 00:05:58 (0.78X)
All operations completed. Total encoding time: 00:05:58
--------------------------------------------------------------------------------
[dj@megajukebox]$ lame cdda.wav -b 256
LAME version 3.50 (www.sulaco.org/mp3)
GPSYCHO: GPL psycho-acoustic model version 0.74.
Encoding ../test.wav to ../test.wav.mp3
Encoding as 44.1 kHz 128 kbps j-stereo MPEG1 LayerIII file
Frame | CPU/estimated | time/estimated | play/CPU | ETA
10756/ 10756(100%)| 0:02:28/ 0:02:28| 0:02:29/ 0:02:29| 1.9074| 0:00:00
--------------------------------------------------------------------------------
[dj@megajukebox]$ gogo cdda.wav -m s -b 256
GOGO-no-coda ver. 2.24 (Feb 12 2000)
Copyright (C) 1999 PEN@MarineCat and shigeo
Special thanks to Keiichi SAKAI, URURI, Noisyu and Kei
MPEG 1, layer 3 stereo
inp sampling-freq=44.1kHz out sampling-freq=44.1kHz bitrate=256kbps
inp sampling-freq=44.1kHz out sampling-freq=44.1kHz bitrate=128kbps
input file `../test.wav'
output file `../test.mp3'
{ 10751/ 10755} 100.0% ( 2.94x) re:[00:00:00.03] to:[00:01:35.42]
End of encoding
time= 95.430sec
Úgy tűnik, hogy a Gogo által használt algoritmus jobban optimalizált, mint a Bladeenc és a Lame által használt.