基于 WordPress | 主题由 mg12 提供 | 通过 XHTML 1.1CSS 3 验证
  • wav、flac 转换 MP3 脚本

    在一个讨论音乐的论坛上找到了这个脚本,写的很不错。解决了 CUE 信息输入 MP3 的问题。因为他 lame 的处理并没有放在 shntool 里面。
    由于单引号的屏蔽, shntool 里面无法将 mp3 tag 输入文件中。此脚本将所有信息全部放在变量里面,再输入。

    该脚本除了之前提到的 shntool 以外还用到了 cueprint 工具包。你可以通过以下命令安装:

    原模板用在最新的 shntool 上有一点错误,我稍许修改了一下。

    apt-get install cuetools



    #!/bin/bash
    echo "Brian's Archive CUE/FLAC Splitter v0.1"
    echo "No sanity checking in place. Be careful."

    #Get the filenames #执行脚本的时候将脚本后跟的第一个文件定义为 cue 文件,第二个文件定义为 flac 文件。
    cuefile=$1
    flacfile=$2

    #Other variables 通过 cueprint 抓取光盘曲目数。 -d 为读取 disc 模板,%N 为曲目数。
    tracks=$(cueprint -d ‘%N’ “$cuefile”)

    #Get the filenames into an array
    #循环读取各个歌曲的信息。
    #cueprint -n$count -t ‘%p - %T - %02n - %t’ “$cuefile” 中,-n 定义曲目号, -t 表示读取歌曲模板,%p 作者,%T 专辑名。
    #%n 为歌曲编号,写为 %02n 则表示长度为2,即01、02。若%05n 则是显示为:00001。
    #%t 为歌曲名。
    count=1
    while [ $count -le $tracks ]
    do
    tracknames[$count]=$(cueprint -n$count -t ‘%p - %T - %02n - %t’ “$cuefile”) #Initialize the tracknames array and write a trackname in
    count=`expr $count + 1` #Increment the counter
    done

    #Load up the ID3 tag info into variables for later use
    #循环读取各个信息放入不同的变量。包括艺术家等。
    id3count=1
    while [ $id3count -le $tracks ]
    do
    artist[$id3count]=$(cueprint -n$id3count -t ‘%p’ “$cuefile”)
    album[$id3count]=$(cueprint -n$id3count -t ‘%T’ “$cuefile”)
    tracknum[$id3count]=$(cueprint -n$id3count -t ‘%02n’ “$cuefile”)
    title[$id3count]=$(cueprint -n$id3count -t ‘%t’ “$cuefile”)
    echo “Artist: ${artist[$id3count]}”
    echo “Album: ${album[$id3count]}”
    echo “Track No: ${tracknum[$id3count]}”
    echo “Song Title: ${title[$id3count]}”
    id3count=$[$id3count + 1]
    done

    #Output general file information
    cueprint -d ‘%P - %T\n’ “$cuefile”
    echo “Total number of tracks: ” $tracks

    #Split this bitch
    cuebreakpoints “$cuefile” | shntool split -t ‘%n’ -o wav “$flacfile” #outputs 01.wav 02.wav, etc

    #Convert those waves into mp3s
    #由于 输出为 wav 文件的时候,number 为 001、002等格式。所以下面补足一下。
    convertcount=1
    while [ $convertcount -le $tracks ]
    do
    if [ $convertcount -lt 10 ] #Got to pad with zeros
    then
    wavenum=0$convertcount
    else
    wavenum=$convertcount
    fi

    #通过 lame 将 wav 转换为 mp3,同时灌入tags。
    #lame –noreplaygain -b 320 “$wavenum.wav” “${tracknames[$convertcount]}.mp3″ #Compress the file and give it the trackname in the array
    lame –noreplaygain -b 320 –ta “${artist[$convertcount]}” –tl “${album[$convertcount]}” –tn “${tracknum[$convertcount]}” –tt “${title[$convertcount]}” “$wavenum.wav” “${tracknames[$convertcount]}.mp3″
    rm ./”$wavenum.wav” #cleanup 删除临时的 wav 文件
    convertcount=$[$convertcount + 1]

    done

    2007年11月2日16:26
  • vvoody
    2008年8月2日10:24 | #1

    嗯,我知道lame可以写入id3。但我那样就不必生成中间wav文件了。

    谢谢你贴的脚本 ;-)

发表评论

XHTML: 您可以使用这些标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">
置顶