下一页 上一页 目录

10. 从 CD-ROM 编码。

与从音频编码类似,从 CD 编码是一个两阶段的过程。首先,从 CD 中提取音频数据并转换为 wav 文件。然后,wav 文件被转换为 MP3。

基本上有两种类型的编码器,基于控制台的和基于 X 窗口系统的。两者都做同样的工作,但是基于 X 窗口系统的编码器更容易使用(并且看起来更漂亮)。

同样,在开始编码之前,请检查您的系统是否有足够的驱动器空间。

10.1 命令行编码

我编写了一个非常简单的 Perl 脚本,可以从 CD 中抓取和编码音轨。


#!/usr/bin/perl

if ($ARGV[0] ne "") {

$count = 1;

do {
 
$cdcap = system("cdparanoia", $count, "/mp3/cdda.wav");
$track = "$ARGV[1]/track".$count.".mp3";
$enc = system("bladeenc  /mp3/cdda.wav $track -br 256000");
$count++;

}
until $count > $ARGV[0];
exit;
}

else {
print "Usage cdriper [no of tracks] [destination directory]\n\n";
}

请注意:上面的脚本非常基础,没有任何花哨的功能,例如错误检查或 CDDB。请随意改进 :)

主要的关注行是


$cdcap = system("cdparanoia", $count, "/mp3/cdda.wav");

此行调用 CD 抓取工具 cdparanoia。Cdparanoia 将原始 CD 音频数据转换为 WAV 格式。

我正在使用 Cdparanoia,但如果您希望使用 CDDA2WAV,命令行将是


$cdcap = system("cdda2wav", $count, "/mp3/cdda.wav");

重要的选项是 $count,它是要抓取的音轨数,然后是输出的 WAV 文件的路径。在我的示例中,这将转到我的 MP3 SCSI 驱动器上的 tmp 目录。

然后使用 Bladeenc 将 WAV 文件转换为 MP3 文件。

我编写这个 Perl 脚本是为了抓取 CD,而无需抓取和编码每个音轨,也无需使用 Cdparanoia 的批处理模式。这减少了所需的可用磁盘空间,因为 Cdparanoia 的批处理模式将抓取整个磁盘,并占用高达 600 兆的空间。

如果您想使用 Lame 或 Gogo,请将编码器行替换为


$enc = system("lame  /mp3/cdda.wav $track -b 256");


$enc = system("gogo  /mp3/cdda.wav $track -b 256");

以下是每个编码器的可用选项的转储。

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

RipEnc

RipEnc 执行与上面的代码相同的任务,但是是用 shell 编写的,并且更易于使用 :)

这就是它的样子。


RipEnc version 0.7, Copyright (C) 1999  Michael J. Parmeley
<mjparme@asde.com>, RipEnc comes with ABSOLUTELY NO WARRANTY


There is currently NO encoding process running in the background
Your encode.log file is 982607 bytes long.

<Enter 'd' for details, 'v' to view the encode log, or 'del' to delete the encode log>


1) Change working directory....................[/megajukebox/tmp]
2) Choose encoder..............................[lame]
3) Choose ripper...............................[cdparanoia]
4) Choose id3 tool.............................[none]
5) Toggle between Manual and CDDB naming.......[manual]
6) Setup XMCD_LIBDIR variable for CDA..........[/var/X11R6/lib/xmcd]
7) Set preferred naming convention.............[artist-name_of_song.mp3]
8) Rip whole CD?...............................[no]
9) Set small hard drive option?................[no]
10) Please select your Cd-Rom device...........[/dev/cdrom]
11) Set the Bitrate for the encoded MP3's......[256]
12) List the files in your working directory
13) Start
14) About
15) Exit
?

CD2MP3

Cd2mp3 是一个单程 cdda 到 MP3 编码器。它会将音频轨道转换为 MP3,而无需生成中间的 wav 文件。

以下是它在操作中的样子


[dj@megajukebox]$ cd2mp3 options ALL
Using language: 1 - English.
Translator: Gustavo Sverzut Barbieri(k-s) <gsbarbieri@hotmail.com>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Cd2Mp3 1.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Author: Gustavo Sverzut Barbieri (k-s) <gsbarbieri@hotmail.com.br>
*** device: -D/dev/cdrom        type: -Icooked_ioctl
*** audio device: /dev/dsp
*** preset: tape
*** copyright: Yes
*** author: 
*** album: 

recording: '1' as 'track-1.mp3' (wait)
        Ok! (recorded)
recording: '2' as 'track-2.mp3' (wait)

当然,您可以从命令行向其提供选项,以下是一个列表


dj@megajukebox]$ cd2mp3 --help

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Cd2Mp3 1.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Author: Gustavo Sverzut Barbieri (k-s) <gsbarbieri@hotmail.com.br>
Usage:
  cd2mp3 options <track_number>="<track name>" ... <track_number>="<track name>"or:  cd2mp3 options ALL  (to record all tracks)
or: cd2mp3 options LIST=<reclist_path>  (to read pairs: <track_number>="<track name>" from a file)
ou: cd2mp3 options PLAY=<track_number> VOL=[0..100] (only plays the track)

Options:
  DEV=<cdrom_device> (default: /dev/cdrom)
  DEV_TYPE=[generic_scsi|cooked_ioctl] (default: cooked_ioctl)
  AUDIO_DEV=<audio_device>  (default:/dev/dsp)
  LANGUAGE=<language_number> (LANGUAGE=help to see supported languages)
  COPYRIGHT=[YES|NO]
  PRESET=[phone|voice|fm|tape|hifi|cd|studio] (PRESET=help will give more info)
  ALBUM="<album's title>"
  AUTHOR="<author's name>"

10.2 基于 GUI 的编码器

基于 GUI 的编码器提供基于控制台的编码的所有功能,但将其全部包装在一个美观易用的界面中。Grip 和 RipperX 在操作上类似,两者都允许您选择 CD 上的一个、几个或所有音轨并进行转换。它们还提供 CDDB 支持,使您可以从服务器检索专辑和音轨信息,并节省您手动输入信息的时间。

10.3 编码器性能

在编码部分,我提到了 3 种不同的编码器:bladeenc、lame 和 gogo。主要的区别在于它们在编码方面的性能(尽管可用选项存在差异,这些选项在前面已列出)。

一个小例子。我从 CD 中抓取了一个音轨,然后使用不同的编码器对其进行了编码。所有编码器都在相同的系统条件下运行,并且都生成了立体声输出 mp3。


[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

看来 Gogo 在编码方面比 Bladeenc 和 Lame 具有更优化的算法。


下一页 上一页 目录