title: Trying to concatenate multiple videos with multiple audio streams using ffmpeg
body: <p>I'm trying to concatenate 3 mp4 videos, each contains 3 audio streams using ffmpeg, since I couldn't merge them with other software because of differences in the codecs private data.</p>
  
  <p>Since the files have different codecs I'm trying to use the concat video filter but I can't seem to get it to work. The output turns out to be an unplayable file. I'm trying to specify the input files, and every media stream, then telling the software to concatenate it and copy it to the output file.</p>
  
  <pre><code>ffmpeg -i A.mp4 -i B.mp4 -i C.mp4 -filter_complex  '[0:0] [0:1] [0:2] [0:3] [1:0] [1:1] [1:2] [1:3] [2:0] [2:1] [2:2] [2:3] concat=n=3:v=1:a=3 [v] [a1] [a2] [a3]'  -map '[v]' -map '[a1]' -map '[a2]'-map '[a3]' output.mp4
  </code></pre>
  
  <p>The complete log:</p>
  
  <pre><code>ffmpeg -i A.mp4 -i B.mp4 -i C.mp4 -filter_complex  '[0:0] [0:1] [0:2] [0:3] [1:0] [1:1] [1:2] [1:3] [2:0] [2:1] [2:2] [2:3] concat=n=3:v=1:a=3 [v] [a1] [a2] [a3]'  -map '[v]' -map '[a1]' -map '[a2]'-map '[a3]' output.mp4
  ffmpeg version 4.1.1 Copyright (c) 2000-2019 the FFmpeg developers
    built with gcc 8.2.1 (GCC) 20190212
    configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
    libavutil      56. 22.100 / 56. 22.100
    libavcodec     58. 35.100 / 58. 35.100
    libavformat    58. 20.100 / 58. 20.100
    libavdevice    58.  5.100 / 58.  5.100
    libavfilter     7. 40.101 /  7. 40.101
    libswscale      5.  3.100 /  5.  3.100
    libswresample   3.  3.100 /  3.  3.100
    libpostproc    55.  3.100 / 55.  3.100
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'A.mp4':
    Metadata:
      major_brand     : mp42
      minor_version   : 512
      compatible_brands: isomiso2avc1mp41
      encoder         : HandBrake 0.10.1 2015030800
    Duration: 01:59:10.12, start: 0.000000, bitrate: 6868 kb/s
      Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 6017 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
      Metadata:
        handler_name    : VideoHandler
      Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 320 kb/s (default)
      Metadata:
        handler_name    : Stereo
      Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 320 kb/s
      Metadata:
        handler_name    : Surround
      Stream #0:3(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s
      Metadata:
        handler_name    : Stereo
  Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'B.mp4':
    Metadata:
      major_brand     : mp42
      minor_version   : 512
      compatible_brands: isomiso2avc1mp41
      encoder         : HandBrake 0.10.1 2015030800
    Duration: 01:12:28.48, start: 0.000000, bitrate: 6846 kb/s
      Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 6001 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
      Metadata:
        handler_name    : VideoHandler
      Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 320 kb/s (default)
      Metadata:
        handler_name    : Stereo
      Stream #1:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 320 kb/s
      Metadata:
        handler_name    : Surround
      Stream #1:3(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s
      Metadata:
        handler_name    : Stereo
  Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'C.mp4':
    Metadata:
      major_brand     : mp42
      minor_version   : 512
      compatible_brands: isomiso2avc1mp41
      encoder         : HandBrake 0.10.1 2015030800
    Duration: 00:58:55.53, start: 0.000000, bitrate: 6850 kb/s
      Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 6005 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
      Metadata:
        handler_name    : VideoHandler
      Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 319 kb/s (default)
      Metadata:
        handler_name    : Stereo
      Stream #2:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 319 kb/s
      Metadata:
        handler_name    : Surround
      Stream #2:3(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s
      Metadata:
        handler_name    : Stereo
  Stream mapping:
    Stream #0:0 (h264) -&gt; concat:in0:v0
    Stream #0:1 (aac) -&gt; concat:in0:a0
    Stream #0:2 (aac) -&gt; concat:in0:a1
    Stream #0:3 (aac) -&gt; concat:in0:a2
    Stream #1:0 (h264) -&gt; concat:in1:v0
    Stream #1:1 (aac) -&gt; concat:in1:a0
    Stream #1:2 (aac) -&gt; concat:in1:a1
    Stream #1:3 (aac) -&gt; concat:in1:a2
    Stream #2:0 (h264) -&gt; concat:in2:v0
    Stream #2:1 (aac) -&gt; concat:in2:a0
    Stream #2:2 (aac) -&gt; concat:in2:a1
    Stream #2:3 (aac) -&gt; concat:in2:a2
    concat:out:v0 -&gt; Stream #0:0 (libx264)
    concat:out:a0 -&gt; Stream #0:1 (aac)
    concat:out:a1 -&gt; Stream #0:2 (aac)
    concat:out:a2 -&gt; Stream #0:3 (aac)
  Press [q] to stop, [?] for help
  [libx264 @ 000001930c898980] using SAR=1/1
  [libx264 @ 000001930c898980] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
  [libx264 @ 000001930c898980] profile High, level 4.0, 4:2:0, 8-bit
  [libx264 @ 000001930c898980] 264 - core 157 r2935 545de2f - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
  Output #0, mp4, to 'output.mp4':
    Metadata:
      major_brand     : mp42
      minor_version   : 512
      compatible_brands: isomiso2avc1mp41
      encoder         : Lavf58.20.100
      Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
      Metadata:
        encoder         : Lavc58.35.100 libx264
      Side data:
        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
      Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
      Metadata:
        encoder         : Lavc58.35.100 aac
      Stream #0:2: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 341 kb/s
      Metadata:
        encoder         : Lavc58.35.100 aac
      Stream #0:3: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
      Metadata:
        encoder         : Lavc58.35.100 aac
  [aac @ 000001930d3a88c0] skip_data_stream_element: Input buffer exhausted before END element found
  Error while decoding stream #0:1: Invalid data found when processing input
  [aac @ 000001930c89a4c0] Number of bands (48) exceeds limit (47).ate=6048.4kbits/s dup=1 drop=0 speed=0.916x
  Error while decoding stream #2:1: Invalid data found when processing input
  frame=450571 fps= 28 q=-1.0 Lsize=11204203kB time=04:10:34.13 bitrate=6105.1kbits/s dup=1 drop=0 speed=0.939x
  video:10071486kB audio:1099256kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.299544%
  [libx264 @ 000001930c898980] frame I:4679  Avg QP:20.30  size:103274
  [libx264 @ 000001930c898980] frame P:125629 Avg QP:22.82  size: 41052
  [libx264 @ 000001930c898980] frame B:320263 Avg QP:25.08  size: 14590
  [libx264 @ 000001930c898980] consecutive B-frames:  2.3%  6.0%  8.8% 83.0%
  [libx264 @ 000001930c898980] mb I  I16..4: 16.4% 78.4%  5.2%
  [libx264 @ 000001930c898980] mb P  I16..4:  7.0% 17.1%  1.1%  P16..4: 43.0%  9.7%  4.9%  0.0%  0.0%    skip:17.3%
  [libx264 @ 000001930c898980] mb B  I16..4:  0.8%  1.7%  0.1%  B16..8: 39.4%  3.6%  0.7%  direct: 4.3%  skip:49.4%  L0:43.8% L1:50.2% BI: 6.0%
  [libx264 @ 000001930c898980] 8x8 transform intra:68.6% inter:84.9%
  [libx264 @ 000001930c898980] coded y,uvDC,uvAC intra: 40.3% 64.9% 17.2% inter: 12.9% 24.2% 0.4%
  [libx264 @ 000001930c898980] i16 v,h,dc,p: 40% 22% 10% 28%
  [libx264 @ 000001930c898980] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 15% 23%  5%  6%  7%  5%  6%  5%
  [libx264 @ 000001930c898980] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 16% 16%  6%  9%  9%  7%  6%  5%
  [libx264 @ 000001930c898980] i8c dc,h,v,p: 48% 20% 26%  6%
  [libx264 @ 000001930c898980] Weighted P-Frames: Y:8.6% UV:6.4%
  [libx264 @ 000001930c898980] ref P L0: 58.8% 12.5% 19.8%  8.4%  0.4%
  [libx264 @ 000001930c898980] ref B L0: 88.5%  9.1%  2.4%
  [libx264 @ 000001930c898980] ref B L1: 96.9%  3.1%
  [libx264 @ 000001930c898980] kb/s:5487.92
  [aac @ 000001930c899280] Qavg: 212.043
  [aac @ 000001930d1cfbc0] Qavg: 211.329
  [aac @ 000001930d1ce080] Qavg: 228.685
  </code></pre>
  
  <p>This is the output when trying the concat demuxer, which also produces an unplayable file.</p>
  
  <pre><code>ffmpeg -f concat -safe 0 -i mylist.txt -map 0 -c copy concat2.mp4
  ffmpeg version 4.1.1 Copyright (c) 2000-2019 the FFmpeg developers
    built with gcc 8.2.1 (GCC) 20190212
    configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
    libavutil      56. 22.100 / 56. 22.100
    libavcodec     58. 35.100 / 58. 35.100
    libavformat    58. 20.100 / 58. 20.100
    libavdevice    58.  5.100 / 58.  5.100
    libavfilter     7. 40.101 /  7. 40.101
    libswscale      5.  3.100 /  5.  3.100
    libswresample   3.  3.100 /  3.  3.100
    libpostproc    55.  3.100 / 55.  3.100
  [mov,mp4,m4a,3gp,3g2,mj2 @ 0000025ca95f2dc0] Auto-inserting h264_mp4toannexb bitstream filter
  Input #0, concat, from 'mylist.txt':
    Duration: N/A, start: 0.000000, bitrate: 6850 kb/s
      Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 6017 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc
      Metadata:
        handler_name    : VideoHandler
      Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 320 kb/s
      Metadata:
        handler_name    : Stereo
      Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 320 kb/s
      Metadata:
        handler_name    : Surround
      Stream #0:3(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s
      Metadata:
        handler_name    : Stereo
  Output #0, mp4, to 'concat2.mp4':
    Metadata:
      encoder         : Lavf58.20.100
      Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 6017 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
      Metadata:
        handler_name    : VideoHandler
      Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 320 kb/s
      Metadata:
        handler_name    : Stereo
      Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 320 kb/s
      Metadata:
        handler_name    : Surround
      Stream #0:3(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s
      Metadata:
        handler_name    : Stereo
  Stream mapping:
    Stream #0:0 -&gt; #0:0 (copy)
    Stream #0:1 -&gt; #0:1 (copy)
    Stream #0:2 -&gt; #0:2 (copy)
    Stream #0:3 -&gt; #0:3 (copy)
  Press [q] to stop, [?] for help
  [mov,mp4,m4a,3gp,3g2,mj2 @ 0000025ca95f9480] Auto-inserting h264_mp4toannexb bitstream filter4x
  [mov,mp4,m4a,3gp,3g2,mj2 @ 0000025ca95f9480] Auto-inserting h264_mp4toannexb bitstream filter5x
  frame=450570 fps=1251 q=-1.0 Lsize=12591157kB time=04:10:34.11 bitrate=6860.8kbits/s speed=41.7x
  video:11029679kB audio:1527897kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.267411%
  </code></pre>