title: FFmpeg - Concat videos with different time base
body: <p>I'm trying to concat videos with the concat demuxer, but it does not work when using one video ("video2.mp4" below). By does not work, I mean playing the concatenated video on a player will work until the second video part starts (it just cannot read the video anymore). It works with the concat filter though. They are both mp4 videos, so I think it's because of the time base ? I can concat other videos with the concat demuxer and it works fine (even with different resolutions/bitrate). It only happens when trying to concat "video2.mp4".</p>
  
  <p>Also, I have a lot of warning/errors like this, probably when ffmpeg starts concatenating the 2nd video :</p>
  
  <pre><code>[mp4 @ 0x7f847a814800] Non-monotonous DTS in output stream 0:0; previous: 906906, current: 302359; changing to 906907. This may result in incorrect timestamps in the output file.
  </code></pre>
  
  <p>What would be the best way to have a minimum concat time ? Do I really need to use the concat filter or can I change the time base of "video1.mp4" if it's really the problem ? </p>
  
  <p>Any help would be appreciated, thanks !</p>
  
  <p>Video 1 :</p>
  
  <pre><code>ffprobe version 3.2.2 Copyright (c) 2007-2016 the FFmpeg developers
    built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
    configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
    libavutil      55. 34.100 / 55. 34.100
    libavcodec     57. 64.101 / 57. 64.101
    libavformat    57. 56.100 / 57. 56.100
    libavdevice    57.  1.100 / 57.  1.100
    libavfilter     6. 65.100 /  6. 65.100
    libavresample   3.  1.  0 /  3.  1.  0
    libswscale      4.  2.100 /  4.  2.100
    libswresample   2.  3.100 /  2.  3.100
    libpostproc    54.  1.100 / 54.  1.100
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video1.mp4':
    Metadata:
      major_brand     : mp42
      minor_version   : 0
      compatible_brands: isommp42
      creation_time   : 2016-08-17T22:50:35.000000Z
    Duration: 00:00:10.11, start: 0.000000, bitrate: 38018 kb/s
      Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1696x848, 37832 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
      Metadata:
        creation_time   : 2016-08-18T00:02:24.000000Z
        handler_name    : VideoHandle
      Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
      Metadata:
        creation_time   : 2016-08-18T00:02:24.000000Z
        handler_name    : SoundHandle 
  </code></pre>
  
  <p>Video 2 :</p>
  
  <pre><code>ffprobe version 3.2.2 Copyright (c) 2007-2016 the FFmpeg developers
    built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
    configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
    libavutil      55. 34.100 / 55. 34.100
    libavcodec     57. 64.101 / 57. 64.101
    libavformat    57. 56.100 / 57. 56.100
    libavdevice    57.  1.100 / 57.  1.100
    libavfilter     6. 65.100 /  6. 65.100
    libavresample   3.  1.  0 /  3.  1.  0
    libswscale      4.  2.100 /  4.  2.100
    libswresample   2.  3.100 /  2.  3.100
    libpostproc    54.  1.100 / 54.  1.100
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video2.mp4':
    Metadata:
      major_brand     : mp42
      minor_version   : 0
      compatible_brands: mp42mp41
      creation_time   : 2017-01-06T22:30:23.000000Z
    Duration: 00:00:08.19, start: 0.000000, bitrate: 101474 kb/s
      Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 4096x2048 [SAR 1:1 DAR 2:1], 101549 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
      Metadata:
        creation_time   : 2017-01-06T22:30:23.000000Z
        handler_name    : ?Mainconcept Video Media Handler
        encoder         : AVC Coding
      Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
      Metadata:
        creation_time   : 2017-01-06T22:30:23.000000Z
        handler_name    : #Mainconcept MP4 Sound Media Handler 
  </code></pre>
  
  <p>FFMpeg Command :</p>
  
  <pre><code>ffmpeg -f concat -safe 0 -i concat.txt -c copy result.mp4
  </code></pre>
  
  <p>concat.txt :</p>
  
  <pre><code>file '/path/to/video1.mp4'
  file '/path/to/video2.mp4' 
  </code></pre>
  
  <p>Command result :</p>
  
  <pre><code>ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
    built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
    configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
    libavutil      55. 34.100 / 55. 34.100
    libavcodec     57. 64.101 / 57. 64.101
    libavformat    57. 56.100 / 57. 56.100
    libavdevice    57.  1.100 / 57.  1.100
    libavfilter     6. 65.100 /  6. 65.100
    libavresample   3.  1.  0 /  3.  1.  0
    libswscale      4.  2.100 /  4.  2.100
    libswresample   2.  3.100 /  2.  3.100
    libpostproc    54.  1.100 / 54.  1.100
  [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fbd8b808c00] Auto-inserting h264_mp4toannexb bitstream filter
  Input #0, concat, from 'concat.txt':
    Duration: N/A, start: 0.000000, bitrate: 38021 kb/s
      Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1696x848, 37832 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc
      Metadata:
        creation_time   : 2016-08-18T00:02:24.000000Z
        handler_name    : VideoHandle
      Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s
      Metadata:
        creation_time   : 2016-08-18T00:02:24.000000Z
        handler_name    : SoundHandle
  Output #0, mp4, to 'result.mp4':
    Metadata:
      encoder         : Lavf57.56.100
      Stream #0:0(eng): Video: h264 (Baseline) ([33][0][0][0] / 0x0021), yuv420p, 1696x848, q=2-31, 37832 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
      Metadata:
        creation_time   : 2016-08-18T00:02:24.000000Z
        handler_name    : VideoHandle
      Stream #0:1(eng): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 189 kb/s
      Metadata:
        creation_time   : 2016-08-18T00:02:24.000000Z
        handler_name    : SoundHandle
  Stream mapping:
    Stream #0:0 -&gt; #0:0 (copy)
    Stream #0:1 -&gt; #0:1 (copy) 
  Press [q] to stop, [?] for help
  frame=  112 fps=0.0 q=-1.0 size=   12701kB time=00:00:03.70 bitrate=28092.2kbits/s speed= 7.4x
  frame=  151 fps=151 q=-1.0 size=   18853kB time=00:00:05.00 bitrate=30857.5kbits/s speed=   5x
  frame=  224 fps=149 q=-1.0 size=   30042kB time=00:00:07.44 bitrate=33074.8kbits/s speed=4.95x
  frame=  268 fps=134 q=-1.0 size=   36596kB time=00:00:08.90 bitrate=33650.8kbits/s speed=4.44x
  [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fbd8a808000] Auto-inserting h264_mp4toannexb bitstream filter.9x 
  [mp4 @ 0xb545d000] Non-monotonous DTS in output stream 0:1; previous: 484352, current: 445939; changing to 484353. This may result in incorrect timestamps in the output file.
  [concat @ 0xb545c400] DTS 304057 &lt; 906906 out of order
  [mp4 @ 0xb545d000] Non-monotonous DTS in output stream 0:0; previous: 906906, current: 304057; changing to 906907. This may result in incorrect timestamps in the output file.
  [mp4 @ 0xb545d000] Non-monotonous DTS in output stream 0:1; previous: 484353, current: 446963; changing to 484354. This may result in incorrect timestamps in the output file.
  ...
  ... like 100 DTS errors ...
  ...
  [mp4 @ 0xb545d000] Non-monotonous DTS in output stream 0:0; previous: 907150, current: 548301; changing to 907151. This may result in incorrect timestamps in the output file.
  frame=  548 fps=169 q=-1.0 Lsize=  148399kB time=00:00:18.28 bitrate=66493.7kbits/s speed=5.64x
  video:148027kB audio:359kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.008622%
  </code></pre>
  
  <p>Thank you in advance !</p>