Answers.Body: <p>What the concat demuxer does is to zero out the starting timestamps of each file and make the last timestamp of a file and the starting timestamp of the next file smooth.</p>
  
  <p>Your files have Vorbis audio, which has a codec delay of 70ms. The difference in total duration is the accumulation of these delays over all segments.</p>
  
  <p>Skip the audio during concat and add it afterwards.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-26T18:04:05.820Z
Answers.LastActivityDate: 2018-04-26T18:04:05.820Z
Answers.UserDisplayName: Gyan
Body: <p>I have 239 small MKV video files with identical characteristics (they were cut from the original video with the same command but different <code>-ss -t</code> parameters).</p>
  
  <p>I concatenate them all back into one long video and this video gets longer duration than the sum of durations of the small files.</p>
  
  <p>All small files have <code>29.95 fps</code> but the concatenated video has <code>29.75 fps</code> and I do the <code>-c copy</code>, why does it change?</p>
  
  <p>How can I concatenate the files and get the expected duration without frame rate change?</p>
  
  <p>I counted frames of all input files and frames of the resulting video and the number of frames is the same, so the problem is in fps.</p>
  
  <p>Also I tried to re-encode instead of copy and get proper 29.95 fps but the duration is still longer than the original, number of frames also increased...</p>
  
  <p>I'm lost here, please advise.</p>
  
  <p>Here is my original <code>concat</code> command:</p>
  
  <pre><code>ffmpeg -f concat -safe 0 -i lst -c copy -y concat.mp4
  </code></pre>
  
  <p>List file 'lst' contains:</p>
  
  <pre><code>file test_000.mkv
  file test_001.mkv
  file test_002.mkv
  ....
  </code></pre>
  
  <p>ffprobe for the first two files, they all differ by duration only:</p>
  
  <pre><code>ffprobe version 4.0-static https://johnvansickle.com/ffmpeg/  
  Copyright (c) 2007-2018 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-libxml2 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
  Input #0, matroska,webm, from 'test_000.mkv':
  Metadata:
  ENCODER         : Lavf58.10.100
  Duration: 00:00:19.07, start: 0.064000, bitrate: 12639 kb/s
  Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 29.95 fps, 29.95 tbr, 1k tbn, 59.90 tbc (default)
  Metadata:
    ENCODER         : Lavc58.14.100 libx264
    DURATION        : 00:00:19.065000000
  Stream #0:1: Audio: vorbis, 48000 Hz, mono, fltp
  Metadata:
    ENCODER         : Lavc58.14.100 libvorbis
    DURATION        : 00:00:19.068000000
  </code></pre>
  
  <p>Second file:</p>
  
  <pre><code>    ffprobe version 4.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2007-2018 the FFmpeg developers
          built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
      configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-libxml2 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
      libavutil      56. 14.100 / 56. 14.100
      libavcodec     58. 18.100 / 58. 18.100
      libavformat    58. 12.100 / 58. 12.100
      libavdevice    58.  3.100 / 58.  3.100
      libavfilter     7. 16.100 /  7. 16.100
      libswscale      5.  1.100 /  5.  1.100
      libswresample   3.  1.100 /  3.  1.100
      libpostproc    55.  1.100 / 55.  1.100
      Input #0, matroska,webm, from 'test_001.mkv':
      Metadata:
          ENCODER         : Lavf58.10.100
      Duration: 00:00:12.07, start: 0.064000, bitrate: 10773 kb/s
      Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 29.95 fps, 29.95 tbr, 1k tbn, 59.90 tbc (default)
      Metadata:
          ENCODER         : Lavc58.14.100 libx264
      DURATION        : 00:00:12.053000000
      Stream #0:1: Audio: vorbis, 48000 Hz, mono, fltp
      Metadata:
          ENCODER         : Lavc58.14.100 libvorbis
      DURATION        : 00:00:12.067000000
  </code></pre>
  
  <p>Resulting video:</p>
  
  <pre><code>ffprobe version 4.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2007-2018 the FFmpeg developers
      built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-libxml2 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'concat.mp4':
  Metadata:
      major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf58.10.100
  Duration: 00:41:23.73, start: 0.000000, bitrate: 9392 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 9313 kb/s, 29.75 fps, 29.97 tbr, 16k tbn, 59.90 tbc (default)
  Metadata:
      handler_name    : VideoHandler
  Stream #0:1(und): Audio: vorbis (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 66 kb/s (default)
  Metadata:
      handler_name    : SoundHandler
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-26T15:42:09.137Z
Comments.Text: The difference is due to the accumulation of the audio delay. What are you altering in the segment files?
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-26T15:50:04.527Z
Comments.Text: The original video has a huge panoramic frame, I cut fullhd parts from it from different places.
Comments.UserDisplayName: Northern Captain
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-26T16:04:43.687Z
Comments.Text: So, no editing of the audio? Run your concat command with audio disabled `-an` and check.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-26T17:22:51.080Z
Comments.Text: You are right, if I remove the audio channel everything becomes fine and the duration is exactly as it should be. Thanks, but I don't understand why this is happening, why it's impossible to cut the audio exactly at the time the video frame ends.
  Now will do the workaround - concat video only and then merge with audio channel from the original full length video.
  Thanks a lot!
Comments.UserDisplayName: Northern Captain
Tags: <ffmpeg>
Title: ffmpeg - concatenate multiple almost identical files ends up in longer video than expected
UserDisplayName: Northern Captain
ThreadText: # ffmpeg - concatenate multiple almost identical files ends up in longer video than expected
  
  (Asked by: username_0 on 2018-04-26)
  
  I have 239 small MKV video files with identical characteristics (they were cut from the original video with the same command but different `-ss -t` parameters).
  
  I concatenate them all back into one long video and this video gets longer duration than the sum of durations of the small files.
  
  All small files have `29.95 fps` but the concatenated video has `29.75 fps` and I do the `-c copy`, why does it change?
  
  How can I concatenate the files and get the expected duration without frame rate change?
  
  I counted frames of all input files and frames of the resulting video and the number of frames is the same, so the problem is in fps.
  
  Also I tried to re-encode instead of copy and get proper 29.95 fps but the duration is still longer than the original, number of frames also increased...
  
  I'm lost here, please advise.
  
  Here is my original `concat` command:
  
  ```
  ffmpeg -f concat -safe 0 -i lst -c copy -y concat.mp4
  
  ```
  
  List file 'lst' contains:
  
  ```
  file test_000.mkv
  file test_001.mkv
  file test_002.mkv
  ....
  
  ```
  
  ffprobe for the first two files, they all differ by duration only:
  
  ```
  ffprobe version 4.0-static https://johnvansickle.com/ffmpeg/  
  Copyright (c) 2007-2018 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-libxml2 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
  Input #0, matroska,webm, from 'test_000.mkv':
  Metadata:
  ENCODER         : Lavf58.10.100
  Duration: 00:00:19.07, start: 0.064000, bitrate: 12639 kb/s
  Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 29.95 fps, 29.95 tbr, 1k tbn, 59.90 tbc (default)
  Metadata:
    ENCODER         : Lavc58.14.100 libx264
    DURATION        : 00:00:19.065000000
  Stream #0:1: Audio: vorbis, 48000 Hz, mono, fltp
  Metadata:
    ENCODER         : Lavc58.14.100 libvorbis
    DURATION        : 00:00:19.068000000
  
  ```
  
  Second file:
  
  ```
      ffprobe version 4.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2007-2018 the FFmpeg developers
          built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
      configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-libxml2 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
      libavutil      56. 14.100 / 56. 14.100
      libavcodec     58. 18.100 / 58. 18.100
      libavformat    58. 12.100 / 58. 12.100
      libavdevice    58.  3.100 / 58.  3.100
      libavfilter     7. 16.100 /  7. 16.100
      libswscale      5.  1.100 /  5.  1.100
      libswresample   3.  1.100 /  3.  1.100
      libpostproc    55.  1.100 / 55.  1.100
      Input #0, matroska,webm, from 'test_001.mkv':
      Metadata:
          ENCODER         : Lavf58.10.100
      Duration: 00:00:12.07, start: 0.064000, bitrate: 10773 kb/s
      Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 29.95 fps, 29.95 tbr, 1k tbn, 59.90 tbc (default)
      Metadata:
          ENCODER         : Lavc58.14.100 libx264
      DURATION        : 00:00:12.053000000
      Stream #0:1: Audio: vorbis, 48000 Hz, mono, fltp
      Metadata:
          ENCODER         : Lavc58.14.100 libvorbis
      DURATION        : 00:00:12.067000000
  
  ```
  
  Resulting video:
  
  ```
  ffprobe version 4.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2007-2018 the FFmpeg developers
      built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-libxml2 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'concat.mp4':
  Metadata:
      major_brand     : isom
  minor_version   : 512
  compatible_brands: isomiso2avc1mp41
  encoder         : Lavf58.10.100
  Duration: 00:41:23.73, start: 0.000000, bitrate: 9392 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 9313 kb/s, 29.75 fps, 29.97 tbr, 16k tbn, 59.90 tbc (default)
  Metadata:
      handler_name    : VideoHandler
  Stream #0:1(und): Audio: vorbis (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 66 kb/s (default)
  Metadata:
      handler_name    : SoundHandler
  
  ```
  
  **Tags:** ffmpeg
  
  > **Comments:**
  > **username_1**: The difference is due to the accumulation of the audio delay. What are you altering in the segment files?  
  > **username_0**: The original video has a huge panoramic frame, I cut fullhd parts from it from different places.  
  > **username_1**: So, no editing of the audio? Run your concat command with audio disabled `-an` and check.  
  > **username_0**: You are right, if I remove the audio channel everything becomes fine and the duration is exactly as it should be. Thanks, but I don't understand why this is happening, why it's impossible to cut the audio exactly at the time the video frame ends. Now will do the workaround - concat video only and then merge with audio channel from the original full length video. Thanks a lot!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-26. Score: 2 | Accepted answer
  
  What the concat demuxer does is to zero out the starting timestamps of each file and make the last timestamp of a file and the starting timestamp of the next file smooth.
  
  Your files have Vorbis audio, which has a codec delay of 70ms. The difference in total duration is the accumulation of these delays over all segments.
  
  Skip the audio during concat and add it afterwards.
  
  
  ---
  
  