如何使用 FFmpeg 合并三个或更多视频输入来创建音频文件

如何使用 FFmpeg 合并三个或更多视频输入来创建音频文件

我正在尝试通过合并多个视频输入来创建音频文件。合并的输入可能指定了 -itsoffset 来确定它们在合并中的开始时间。

我不确定为什么 3 个输入不起作用。几乎相同的命令适用于两个输入。当我有 3 个输入时,我收到错误:

[libmp3lame @ 0x2b55d60] Specified channel layout '2.1' is not supported

我认为错误意味着不支持超过 2 个通道的输入。我理解的对吗?我需要一次合并两个输入吗?我考虑先将所有三个输入合并为一个视频,然后将完成的视频文件转换为音频文件。但我认为避免视频转换会更明智,因为我最终只想要一个音频文件。

具有 2 个输入的命令有效:

ffmpeg -itsoffset 0.5 -i 850_segment_0_remote_0.webm \
       -i 850_segment_0_local_0.webm  \
       -filter_complex " [0:a][1:a]amerge=inputs=2[a]" \
       -map "[a]" -ac 2 -ar 44100 -strict -2 \
       -acodec libmp3lame 850_segment_0.mp3

带有 3 个输入的命令失败:

ffmpeg -itsoffset 8.698 -i 850_segment_1_remote_0.webm -itsoffset 9.705 \
       -i 850_segment_1_remote_1.webm -i 850_segment_1_local_0.webm \
       -filter_complex " [0:a][1:a][2:a]amerge=inputs=3[a]" \
       -map "[a]" -ac 3 -ar 44100 -strict -2 \
       -acodec libmp3lame 850_segment_1.mp3

ffmpeg version 3.0.git Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.2) 20160609
  configuration: --prefix=/home/daryl/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/daryl/ffmpeg_build/include --extra-ldflags=-L/home/daryl/ffmpeg_build/lib --bindir=/home/daryl/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      55. 32.100 / 55. 32.100
  libavcodec     57. 63.103 / 57. 63.103
  libavformat    57. 52.100 / 57. 52.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 64.100 /  6. 64.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  2.100 /  2.  2.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, matroska,webm, from '850_segment_1_remote_0.webm':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
    Stream #0:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Input #1, matroska,webm, from '850_segment_1_remote_1.webm':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #1:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
    Stream #1:1(eng): Video: vp8, yuv420p, 480x640, SAR 1:1 DAR 3:4, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Input #2, matroska,webm, from '850_segment_1_local_0.webm':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #2:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
    Stream #2:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 29.97 fps, 29.97 tbr, 1k tbn, 1k tbc (default)
[Parsed_amerge_0 @ 0x2b56680] No channel layout for input 1
[Parsed_amerge_0 @ 0x2b56680] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
[libmp3lame @ 0x2b55d60] Specified channel layout '2.1' is not supported
Stream mapping:
  Stream #0:0 (opus) -> amerge:in0
  Stream #1:0 (opus) -> amerge:in1
  Stream #2:0 (opus) -> amerge:in2
  amerge -> Stream #0:0 (libmp3lame)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

感谢@Mulvya!

两个有效的命令版本:

ffmpeg -itsoffset 8.698 -i 850_segment_1_remote_0.webm \
       -itsoffset 9.705 -i 850_segment_1_remote_1.webm \
       -i 850_segment_1_local_0.webm \
       -filter_complex " [0:a][1:a][2:a]amerge=inputs=3[a]" \
       -map "[a]" -ac 2 -ar 44100 -strict -2 \
       -acodec libmp3lame 850_segment_1.mp3

ffmpeg -itsoffset 8.698 -i 850_segment_1_remote_0.webm \
       -itsoffset 9.705 -i 850_segment_1_remote_1.webm \
       -i 850_segment_1_local_0.webm \
       -filter_complex " [0:a][1:a][2:a]amerge=inputs=3[a]" \
       -map "[a]" -ac 3 -ar 44100 -strict -2 \
       -acodec aac 850_segment_1.m4a

答案1

MP3 不支持超过 2 个声道。请更改-ac 3-ac 2或选择其他音频编解码器,例如 AAC。

相关内容