Loading [MathJax]/jax/element/mml/optable/BasicLatin.js

Sunday, May 10, 2009

[总结] Linux 下 flac/ape/mp3的转换

需要的软件: shntool, eyed3, mac, flac, cuetools

众所周知, ape由于版权原音, linux下很多软件都不支持, 而网上流传的lossless format很多都是ape,
特别是verycd上的 -,-
for me, 最重要的原因是: mocp 只支持flac, 因此我要把下载回来的东东做成flac或转成320K的mp3, 并可能会分轨.
下面提供我的解决方案.

1. [flac|ape]+cue分轨转成mp3
这里在我上一篇post已经提到了.不再赘述.

2.  [flac|ape]+cue分轨转成[flac|ape]
虽然说320Kbps正常的地球人已经听不出音质的损耗了, 但不排除有人是从那美克星来的...
linux下很多播放器不支持cue(audacious支持很好!见这里)
于是就有了这个必要.

原理其实与1差不多,但是有一个问题,就是ape分轨貌似会有问题....我不想看什么问题,毕竟我只需要转成flac.
直接给code吧
<code>
#!/bin/bash
cuefile="$1"
filename="$2"
filetype="$3"
shntool split -t '%p-%a-%n-%t' -f "cuefile" -o "filetype" "$filename"
tagfromcue "cuefile" "filetype"
</code>

其中tagfromcue是update id3tag用的,代码如下:
<code>
#!/bin/bash

cuefile="1" filetype="2"
tracks=(cueprint -d '%N' "cuefile")

#ID3 tag MP3 files
i=1
while [ i -le tracks ]; do
    artist[i]=(cueprint -ni -t '%P' "cuefile")
    # note that P=album performer, p=track performer
    # and sometimes P may be empty
    # since artist is the starting string of file and '-' is not allowed at first
    # we need fill some stuff to prevent error... set as unknown
    if [ -z "{artist[$i]}" ];then         artist[i]=(cueprint -ni -t '%p' "cuefile")         if [ -z "{artist[i]}" ];then             artist[i]="Unknown"
        fi
    fi
    album[i]=(cueprint -ni -t '%T' "cuefile")
    tracknum[i]=(cueprint -ni -t '%02n' "cuefile")
    title[i]=(cueprint -ni -t '%t' "cuefile")
    f="{artist[$i]}"-"{album[i]}"-"{tracknum[i]}"-"{title[i]}"."filetype"
    echo "setting tag of " "f"     eyeD3 --no-color --set-encoding=utf8 -a "{artist[i]}" -A "{album[i]}" -n "{tracknum[i]}" -t "{title[i]}" "f"
    i=[i+1]
done
</code>

3. 单轨的ape 转 flac
直接使用mac来完成.写成script比较方便
<code>
#!/bin/bash
filename="$1"
mac "1" - -d | flac --best - -o "{filename/%ape/flac}"
<code>

最后可以再用find wrap之, 作用是把当前目录下的所有ape转成flac.
find . -iname "*.ape" -execdir ape2flac {} \;


参考资料:
  1. ubuntu linux下使用.cue对flac/ape分轨及转码
  2. APE转FLAC
  3. http://blog.chinaunix.net/u1/55011/showart_1132760.html

2 comments:

you never know said...

拜师兄..

PS:师兄好帅.

Ivan Z. G. Xiao said...

谢谢

顺便恭喜你破墙而入 -。-