当前位置: 首页 > 知识库问答 >
问题:

如何使用NReco、ffmpeg、ConvertMedia或仅使用ffmpeg命令行组合2个视频?

鄢英哲
2023-03-14

我们有两个视频:video1.webm和video2.webm。如何将这两者结合起来,得到包含来自video1.webm的视频和来自video1和video2的音频的output.mp4?

示例:

video1(video1中的audio1)+video2(video2中的audio2)=outputVideo(video1+audio1+audio2)

图像示例

FFMPEG-i 1.webm-i 2.webm ffmpeg版本N-81872-gbe1d324版权所有(c)2000-2016使用gcc 5.4.0(gcc)配置构建的ffmpeg开发人员:--enable-gpl--enable-version3--disable-w32threads--enable-dxva2--enable-libmfx--enable-nvenc--enable-avisynth--enable-bzlib-enable-libebur128--enable-fontconfig--enable-frei0r--enable-gnutls--enable-libbluray--enable-libbs2b--enable-libfreetype--enable-libgme--enable-libgmbc--enable-libmp3l,AME--enable-libopencore-amrnb--enable-libopencore-amrwb--enable-libopenh264--enable-libopenjpeg--enable-libopus-enable-libopenh264--enable-libopenjpeg--enable-libpopus-enable-librtmp--enable-libschroedinger--enable-libsnappy--enable-libsnappy--enable-libsspeex--enable-libstheora--enable-libtwolame--enable-libvidstab--enablexvid--enable-libzimg--enable-lzma--enable-decklink--enable-zliblibavutil 55。32.100/55。32.100 libavcodec 57。60.101/57。60.101 libavformat 57。51.102/57。51.102 libavdevice 57。0.102/57。0.102 libavfilter 6。63.100/6。63.100 libswscale 4。1.100/4。1.100 libswresample 2。2.100/2。2.100 libpostproc 54。0.100/54。0.100输入#0,马特罗斯卡、韦伯姆、来自“1.WebM”:元数据:编码器:libwebm-0.2.1.0creation_time:2016-10-05T07:54:05.064000 z持续时间:00:00:3.11,开始:0.000000,比特率:798 KB/s流#0:0(eng):音频:opus,48000 Hz,单声道,fltp(默认)流#0:1(eng):视频:vp8,yuv420p,640x480,SAR 1:1 DAR 4:3,8.33tbr,1K tbn,1K tbc(默认)输入#1,matroska,webm,来自'2.webm':metadata:encoder:libwebm-0.2.1.0creation_time:2016-10-05T07:54:20.135000 z持续时间:00:00:30。20,开始:0.000000,比特率:523 kb/s流#1:0(eng):音频:opus,48000 Hz,单声道,fltp(默认)流#1:1(eng):视频:vp8,yuv420p,640x480,SAR 1:1 DAR 4:3,1K tbr,1K tbn,1K tbc(默认)至少必须指定一个输出文件

视频2和视频1没有声音,但很糟糕。长时间转换的过程

>ffmpeg -i 1.webm -i 2.webm -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" -ac 2 -shortest output.webm
ffmpeg version N-81872-gbe1d324 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 32.100 / 55. 32.100
  libavcodec     57. 60.101 / 57. 60.101
  libavformat    57. 51.102 / 57. 51.102
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 63.100 /  6. 63.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 '1.webm':
  Metadata:
    encoder         : libwebm-0.2.1.0
    creation_time   : 2016-10-05T07:54:05.064000Z
  Duration: 00:00:30.11, start: 0.000000, bitrate: 798 kb/s
    Stream #0:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
    Stream #0:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 8.33 tbr, 1k tbn, 1k tbc (default)
Input #1, matroska,webm, from '2.webm':
  Metadata:
    encoder         : libwebm-0.2.1.0
    creation_time   : 2016-10-05T07:54:20.135000Z
  Duration: 00:00:30.20, start: 0.000000, bitrate: 523 kb/s
    Stream #1:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
    Stream #1:1(eng): Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 1k tbr, 1k tbn, 1k tbc (default)
[Parsed_amerge_0 @ 00000000026d4400] No channel layout for input 1
[Parsed_amerge_0 @ 00000000026d4400] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
[libvpx-vp9 @ 0000000002592280] v1.6.0
[libopus @ 00000000024d81e0] No bit rate set. Defaulting to 96000 bps.
Output #0, webm, to 'output.webm':
  Metadata:
    encoder         : Lavf57.51.102
    Stream #0:0(eng): Video: vp9 (libvpx-vp9), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=-1--1, 200 kb/s, 8.33 fps, 1k tbn, 8.33 tbc (default)
    Metadata:
      encoder         : Lavc57.60.101 libvpx-vp9
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: opus (libopus), 48000 Hz, stereo, flt, 96 kb/s (default)
    Metadata:
      encoder         : Lavc57.60.101 libopus
Stream mapping:
  Stream #0:0 (opus) -> amerge:in0 (graph 0)
  Stream #1:0 (opus) -> amerge:in1 (graph 0)
  Stream #0:1 -> #0:0 (vp8 (native) -> vp9 (libvpx-vp9))
  amerge (graph 0) -> Stream #0:1 (libopus)
Press [q] to stop, [?] for help
Error while decoding stream #0:0: Cannot allocate memory94 bitrate=  91.8kbits/s speed=2.33x
    Last message repeated 4 times
Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 100.0kbits/s speed=1.62x
    Last message repeated 23 times
Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 133.1kbits/s speed=1.27x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 160.5kbits/s speed=1.06x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 164.1kbits/s speed=0.932x
    Last message repeated 23 times
Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 185.8kbits/s speed=0.819x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory94 bitrate= 212.5kbits/s speed=0.72x
    Last message repeated 4 times
Error while decoding stream #0:0: Cannot allocate memory28 bitrate= 242.0kbits/s speed=0.68x
    Last message repeated 18 times
Error while decoding stream #0:0: Cannot allocate memory50 bitrate= 190.1kbits/s speed= 0.9x
    Last message repeated 13 times
Error while decoding stream #0:0: Cannot allocate memory50 bitrate= 205.9kbits/s speed=0.849x
    Last message repeated 21 times
Error while decoding stream #0:0: Cannot allocate memory50 bitrate= 209.5kbits/s speed=0.781x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory50 bitrate= 225.2kbits/s speed=0.741x
    Last message repeated 16 times
Error while decoding stream #0:0: Cannot allocate memory50 bitrate= 240.9kbits/s speed=0.695x
    Last message repeated 18 times
Error while decoding stream #0:0: Cannot allocate memory68 bitrate= 239.9kbits/s speed=0.665x
Error while decoding stream #0:0: Cannot allocate memory76 bitrate= 251.1kbits/s speed=0.659x
    Last message repeated 10 times
Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 211.2kbits/s speed=0.791x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 212.8kbits/s speed=0.751x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 224.7kbits/s speed=0.724x
    Last message repeated 11 times
Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 225.4kbits/s speed=0.701x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 235.8kbits/s speed=0.678x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory99 bitrate= 244.0kbits/s speed=0.654x
    Last message repeated 12 times
Error while decoding stream #0:0: Cannot allocate memory16 bitrate= 242.8kbits/s speed=0.645x
    Last message repeated 1 times
Error while decoding stream #0:0: Cannot allocate memory00 bitrate= 242.9kbits/s speed=0.638x
Error while decoding stream #0:0: Cannot allocate memory36 bitrate= 246.9kbits/s speed=0.639x
    Last message repeated 8 times
Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 218.2kbits/s speed=0.727x
    Last message repeated 16 times
Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 219.9kbits/s speed=0.707x
    Last message repeated 11 times
Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 227.5kbits/s speed=0.69x
    Last message repeated 18 times
Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 229.6kbits/s speed=0.673x
    Last message repeated 11 times
Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 237.3kbits/s speed=0.657x
    Last message repeated 16 times
Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 238.8kbits/s speed=0.642x
    Last message repeated 11 times
Error while decoding stream #0:0: Cannot allocate memory46 bitrate= 245.4kbits/s speed=0.627x
    Last message repeated 9 times
Error while decoding stream #0:0: Cannot allocate memory76 bitrate= 242.9kbits/s speed=0.625x
    Last message repeated 1 times
Error while decoding stream #0:0: Cannot allocate memory60 bitrate= 246.0kbits/s speed=0.618x
Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 229.5kbits/s speed=0.697x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 235.1kbits/s speed=0.679x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 236.4kbits/s speed=0.664x
    Last message repeated 11 times
Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 241.4kbits/s speed=0.652x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 242.8kbits/s speed=0.639x
    Last message repeated 11 times
Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 247.9kbits/s speed=0.627x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory97 bitrate= 249.4kbits/s speed=0.616x
    Last message repeated 8 times
Error while decoding stream #0:0: Cannot allocate memory24 bitrate= 252.4kbits/s speed=0.611x
    Last message repeated 4 times
Error while decoding stream #0:0: Cannot allocate memory96 bitrate= 253.9kbits/s speed=0.612x
Error while decoding stream #0:0: Cannot allocate memory32 bitrate= 252.1kbits/s speed=0.611x
    Last message repeated 15 times
Error while decoding stream #0:0: Cannot allocate memory45 bitrate= 233.6kbits/s speed=0.663x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory45 bitrate= 239.7kbits/s speed=0.652x
    Last message repeated 17 times
Error while decoding stream #0:0: Cannot allocate memory45 bitrate= 245.3kbits/s speed=0.641x
    Last message repeated 23 times
Error while decoding stream #0:0: Cannot allocate memory45 bitrate= 246.6kbits/s speed=0.629x
    Last message repeated 25 times
Error while decoding stream #0:0: Cannot allocate memory60 bitrate= 251.4kbits/s speed=0.621x
    Last message repeated 8 times
Error while decoding stream #0:0: Cannot allocate memory80 bitrate= 254.7kbits/s speed=0.629x
    Last message repeated 18 times
Error while decoding stream #0:0: Cannot allocate memory93 bitrate= 239.0kbits/s speed=0.676x
    Last message repeated 29 times
Error while decoding stream #0:0: Cannot allocate memory93 bitrate= 243.4kbits/s speed=0.663x
    Last message repeated 21 times
Error while decoding stream #0:0: Cannot allocate memory93 bitrate= 247.8kbits/s speed=0.655x
    Last message repeated 13 times
Error while decoding stream #0:0: Cannot allocate memory93 bitrate= 252.1kbits/s speed=0.644x
    Last message repeated 15 times
Error while decoding stream #0:0: Cannot allocate memory17 bitrate= 251.6kbits/s speed=0.642x
    Last message repeated 4 times
Error while decoding stream #0:0: Cannot allocate memory44 bitrate= 253.6kbits/s speed=0.64x
    Last message repeated 4 times
Error while decoding stream #0:0: Cannot allocate memory40 bitrate= 254.2kbits/s speed=0.644x
    Last message repeated 5 times
frame=  249 fps=5.4 q=0.0 Lsize=     946kB time=00:00:30.12 bitrate= 257.2kbits/s speed=0.654x
video:806kB audio:133kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.632650%

共有1个答案

禄奇希
2023-03-14

使用amerge将两个音频输入组合成一个输出流,然后使用-map选择所需的流:

ffmpeg -i video0 -i video1 -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" -ac 2 -shortest output

>

  • Amerge默认值是inputs=2,但我还是添加了它,因为我经常看到用户在尝试合并两个以上的流时,假设它是自动的。

    两个输入都是单声道,因此amerge将作出立体声输出。这使得我添加的-ac2变得多余,但我还是添加了它,以防您想合并两个立体声输入。否则,amerge将作出一个4通道输出,而Opus不支持,或至少编码器不支持;假设你想要作品输出。

    如果您得到不能分配内存添加afifo:

    "[0:a]afifo[af];[af][1:a]amerge=inputs=2[a]"
    

    或者试试Amix:

    "[0:a][1:a]amix=inputs=2:duration=shortest[a]"
    

  •  类似资料:
    • 我想把2个视频合成一个视频并排放。我还希望为每个视频设置开始/停止时间。最终视频应为H264/AAC编解码和mp4格式。我附上了样本视频。https://www.dropbox.com/s/e5eouyrrqsy44ts/1.webm?dl=0 https://www.dropbox.com/s/u0zqie0icxamt3q/2.webm?dl=0 我使用了下面的ffmpeg命令。 ffmpeg

    • 我想合并两个视频。两者都有相同的决心。第二个视频没有任何音频 ffmpeg-itest.mp4-ipicture.mp4-filter_complex"[0: v][0: a][1: v][1: a]conat=n=1: v=2: a=1[v][a]"-map"[vv]"-map"[aa]"mergedVideo.mp4 这是我正在使用的命令,但我得到了以下错误流说明符:filtergraph d

    • 我有ffmpeg命令,我想要添加anullsrc过滤器到它 我尝试在不同的地方添加该命令,但总是有问题。命令是取2部电影并将它们并排合并到一部电影中。音频是两部电影一起播放的。 这是命令: ffmpeg-i loop2.mp4-i loop1.mp4-i logo.png-filter_complex“[0:v]pad=width=iw+20:height=ih+20:x=10:y=10:colo

    • 我正在尝试使用FFMPEG将批量的png图像转换成单个mp4 x264视频。由于我不想讨论的原因,转换将帧组转换成短的mp4块,然后我想以特定的fps(在本例中为30fps)将这些块合并到最终的视频中。 我对ffmpeg和x264选项的理解太有限了,虽然我可以毫不费力地从源png帧中生成单个mp4块,但最终合并总是以复制和/或删除帧告终,尤其是非常短的块(<4帧)。 concat.txt: 然后运

    • 我已经使用程序youtube-dl下载了一个YouTube播放列表,我选择了单独下载视频和音频,我现在有一个文件夹充满了视频及其相应的音频,我希望与ffmpeg合并在一起。 我需要使用批处理脚本来执行此操作,但问题是youtube-dl在原始文件的标题之后添加了临时字母,因此视频与其对应的音频没有相同的名称,文件名如下所示: 如何使用windows批处理脚本和ffmpeg合并这些多个视频/音频文件