FFmpeg 中的 amix 过滤器根据 mp3 输入而失败

amix filter in FFmpeg fails depending on the mp3 inputs

在 android 应用程序中,我使用 amix 过滤器合并两个 mp3 文件。现在,有时它可以工作,有时它会给出 "out of memory" 错误,具体取决于它采用的是哪对 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]

这两对文件有什么不同,导致一个失败而另一个有效?

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