FFmpeg中的amix过滤器失败,具体取决于mp3输入

时间:2017-02-10 12:26:58

标签: android ffmpeg mp3

在Android应用程序中,我使用amix过滤器来合并两个mp3文件。现在,有时它会工作,有时它会产生“内存不足”错误,具体取决于它所需的mp3输入对。我在这里粘贴FFmpeg日志,用于合并两个不同的mp3文件的两个不同的执行。

因内存不足而失败:

Input #0, mp3, from '/storage/emulated/0/beatmachine/esplode/1.mp3':
  Duration: 00:00:00.37, start: 0.000000, bitrate: 137 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
[mp3 @ 0xb5b9f600] Skipping 0 bytes of junk at 417.
Input #1, mp3, from '/storage/emulated/0/beatmachine/esplode/7.mp3':
  Duration: 00:00:01.78, start: 0.000000, bitrate: 129 kb/s
    Stream #1:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
Output #0, mp3, to '/storage/emulated/0/beatmachine/esplode/8.mp3':
  Metadata:
    TSSE            : Lavf57.25.100
    Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp (default)
    Metadata:
      encoder         : Lavc57.24.102 libmp3lame
Stream mapping:
  Stream #0:0 (mp3) -> amix:input0
  Stream #1:0 (mp3) -> amix:input1
  amix -> Stream #0:0 (libmp3lame)
Press [q] to stop, [?] for help
Error while filtering: Out of memory
size=       5kB time=00:00:00.36 bitrate= 105.0kbits/s speed=1.51x    
video:0kB audio:4kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 5.548245%

这样可行:

Input #0, mp3, from '/storage/emulated/0/beatmachine/esplode/2.mp3':
  Duration: 00:00:01.36, start: 0.025057, bitrate: 195 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 195 kb/s
[mp3 @ 0xb5c5f600] Skipping 0 bytes of junk at 417.
Input #1, mp3, from '/storage/emulated/0/beatmachine/esplode/4.mp3':
  Duration: 00:00:00.21, start: 0.000000, bitrate: 143 kb/s
    Stream #1:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
Output #0, mp3, to '/storage/emulated/0/beatmachine/esplode/8.mp3':
  Metadata:
    TSSE            : Lavf57.25.100
    Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp (default)
    Metadata:
      encoder         : Lavc57.24.102 libmp3lame
Stream mapping:
  Stream #0:0 (mp3) -> amix:input0
  Stream #1:0 (mp3) -> amix:input1
  amix -> Stream #0:0 (libmp3lame)
Press [q] to stop, [?] for help
size=       7kB time=00:00:00.73 bitrate=  79.6kbits/s speed=1.45x    
size=      13kB time=00:00:01.33 bitrate=  77.0kbits/s speed=1.76x    
video:0kB audio:12kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.010969%

这是我传给FFmpeg的参数:

[-i, input1, -i, input2, -filter_complex, amix=inputs=2:duration=longest[aout], -map, [aout], -ac, 2, -c:a, libmp3lame, -q:a, 9, outputmp3]

两对文件有什么不同,以便一个失败而另一个有效?

1 个答案:

答案 0 :(得分:0)

我最终发现了发生了什么。当第一个输入比第二个输入短时,它会给出out of memory错误,并且输出是在第一个输出结束时截断的mp3文件,尽管在ffmpeg命令中我指定了duration=longest。 我的解决方案就是计算最长输入并将其设置为第一个。我也相信这是我使用的ffmpeg版本的一个错误,我希望它在新版本中得到纠正。