使用Python将avconv转码为96k mp2至256k mp2

时间:2015-07-28 20:05:48

标签: python audio avconv bitrate

我的旧Digigram声卡在尝试交叉淡化不同比特率的音频时有时会失败。我尝试使用python转换所有新的东西,以匹配我们现有的256k MP2。转换WAV和MP3工作得很好,但MP2失败了。文件输出是空白音频或乱码。这是我的代码:

def convertfile(audiofile):
    print "\n\nConverting " + audiofile + "...\n\n"
    firstname = audiofile.split(".")[0]
    extension = audiofile.split(".")[-1]
    try:
        print "converting: " + audiofile + "\n        to: " + firstname + ".WAV\n\n"
        call(['avconv', '-y', '-i', audiofile, '-acodec', 'mp2', '-b', '256k', firstname + ".WAV"])

我得到以下输出:

avconv version 9.14-6:9.14-1rpi1rpi1, Copyright (c) 2000-2014 the Libav developers
  built on Jul 22 2014 15:08:12 with gcc 4.6 (Debian 4.6.3-14+rpi1)
[mp3 @ 0x1881620] max_analyze_duration reached
[mp3 @ 0x1881620] Estimating duration from bitrate, this may be inaccurate
Guessed Channel Layout for  Input Stream #0.0 : mono
Input #0, mp3, from 'file1.mp2':
  Duration: 00:01:02.20, start: 0.000000, bitrate: 96 kb/s
    Stream #0.0: Audio: mp2, 44100 Hz, mono, s16p, 96 kb/s
Output #0, wav, to 'file1.WAV':
  Metadata:
    ISFT            : Lavf54.20.4
    Stream #0.0: Audio: mp2, 44100 Hz, mono, s16, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mp2 -> mp2)
Press ctrl-c to stop encoding
Input stream #0:0 frame changed from rate:44100 fmt:s16p ch:1 chl:mono to rate:44100 fmt:s16 ch:1 chl:mono
incomplete frametime=49.31 bitrate= 255.2kbits/s
Error while decoding stream #0:0
size=    1944kB time=62.19 bitrate= 256.1kbits/s
video:0kB audio:1944kB global headers:0kB muxing overhead 0.005627%

如果我读得正确,avconv似乎认为它正在转换MP3。我还没有办法解决这个问题。也许这是别的东西。我真的不确定。非常感谢任何帮助!

0 个答案:

没有答案