0
votes

We have 2 videos: video1.webm and video2.webm. How to combine these two and get output.mp4 which contains video from video1.webm and audio from video1 and video2?

Example:

video1(audio1 in video1) + video2(audio2 in video2) = outputVideo(video1 + audio1 +audio2)

image example

ffmpeg -i 1.webm -i 2.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) At least one output file must be specified.

No sound from video 2, video 1 but it is very bad. The process of converting long.

>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
You need to show the complete console output of: ffmpeg -i video1 -i video2llogan
I added console output for ffmpeg -i 1.webm -i 2.webmM. Ilchuk

1 Answers

0
votes

Use amerge to combine both audio inputs into one output stream then choose what streams you want with -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 default is inputs=2 but I added it anyway because I often see users assuming it is automatic when they try to merge more than two streams.

  • Both inputs are mono, so therefore amerge will make a stereo output. That makes the -ac 2 I added superfluous, but I added it anyway in case you want to merge two stereo inputs. Otherwise amerge would make a 4 channel output which Opus does not support, or at least the encoder does not; assuming you want Opus output.

  • If you get Cannot allocate memory add afifo:

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

    or try amix:

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