<p>As per <a href="https://trac.ffmpeg.org/wiki/Concatenate" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/Concatenate</a></p>

<p>I had this same issue.  I'm running ffmpeg version 2.6.3 on a mac.  I converted my source clips to the .MTS format with an added tag of -q 0, updated the extensions in the text file and set my output file to a .MTS when I ran the concat command in ffmpeg.  It worked like a charm.  Here is my workflow.</p>

<pre><code>ffmpeg -i clip-1.MOV -q 0 clip-1.MTS

ffmpeg -i clip-2.MOV -q 0 clip-2.MTS
</code></pre>

<p>updated the text file (mylist.txt) to read:</p>

<pre><code>file clip-1.MTS
file clip-2.MTS
</code></pre>

<p>then ran the concat command as follows:</p>

<pre><code>ffmpeg -f concat -i mylist.txt -c copy output.MTS
</code></pre>

<p>Worked for me! You can convert the final output.MTS to whatever format you need.</p>

CC BY-SA 4.0
2018-06-03T15:22:28.993Z
is this protocol lossless?
a06e
CC BY-SA 4.0
2019-01-18T04:33:40.143Z
No, the first command converts to MPEG-2 which doesn't have a lossless mode.
Gyan
CC BY-SA 3.0
2017-12-01T22:41:11.737Z
2017-12-02T01:14:35.473Z
2017-12-02T01:14:35.473Z
Duncan Lindsey
<p>I got similar errors, and the audio in my output videos was sometimes out of sync and sometimes missing completely, but I ended up using <code>mkvmerge</code> from mkvtoolnix instead.</p>

<p>My input videos had been encoded with different settings and they had different dimensions, so I first resized and re-encoded them using <code>ffmpeg</code>:</p>

<p><code>for f in *.mp4;do w=1280;h=720;ffmpeg -i $f -filter:v "scale=iw*min($w/iw\,$h/ih):ih*min($w/iw\,$h/ih),pad=$w:$h:($w-iw*min($w/iw\,$h/ih))/2:($h-ih*min($w/iw\,$h/ih))/2" -c:v libx264 -crf 22 -preset slow -pix_fmt yuv420p -c:a libfdk_aac -vbr 3 -ac 2 -ar 44100 ${f%mp4}mkv;done</code></p>

<p>Some of my input videos didn't have an audio channel, so I used a command like this to add a silent audio channel to them:</p>

<p><code>for f in *.mkv;do ffprobe $f|&amp;grep -q '1: Audio'||ffmpeg -i $f -f lavfi -i anullsrc -c:a libfdk_aac -shortest -c:v copy temp-$f;mv {temp-,}$f;done</code></p>

<p>After that I concatenated the videos:</p>

<pre><code>mkvmerge -o /tmp/output.mkv $(printf %s\\n *.mkv|sed '1!s/^/+/')
</code></pre>

<p>If your input files have the same dimensions, the same number of audio channels, the same audio sample rate, and so on, you can use just <code>mkvmerge</code> to concatenate the files losslessly. The input files for <code>mkvmerge</code> can also have an MP4 container but the output file will have an MKV container even if its filename extension is specified as <code>.mp4</code>. You can run <code>ffmpeg -i output.mkv -c copy output.mp4</code> to change the container.</p>

<p><code>mkvmerge</code> has a syntax like <code>mkvmerge -o output.mkv file1.mkv + file2.mkv + file3.mkv</code>, where <code>mkvmerge -o output.mkv file1.mkv +file2.mkv +file3.mkv</code> is also accepted.</p>

CC BY-SA 4.0
2016-08-07T23:24:23.883Z
2019-01-26T08:33:00.033Z
2019-01-26T08:33:00.033Z
nisetama
<p>Based on Duncan's really helpful answer:</p>
<pre><code>for f in *.mp4; do ffmpeg -i ${f} -q 0 &quot;${f%.*}.mts&quot;; done
</code></pre>
<p>Then this:</p>
<pre><code>ffmpeg -f concat -safe 0 -i &lt;(for f in *.mts; do echo &quot;file '$PWD/${f}'&quot;; done) -c copy All.mts
</code></pre>
<p>Or if videos are all the same format:</p>
<pre><code>ffmpeg -f concat -safe 0 -i &lt;(find . -name '*.mp4' -printf &quot;file '$PWD/%p'\n&quot; | sort) -c copy all.mp4
</code></pre>

CC BY-SA 4.0
2022-09-06T19:26:24.710Z
That final command should search for the `.mts` files made in step one, not the original mp4s. So: `ffmpeg -f concat -safe 0 -i <(find . -name '*.mts' -printf "file '$PWD/%p'\n" | sort) -c copy all.mp4`
gbanks
CC BY-SA 4.0
2019-01-08T16:45:14.247Z
2021-03-12T18:58:37.693Z
2021-03-12T18:58:37.693Z
Hans-J. Schmid
<p>Ok, here's an answer that has worked well for me (as well as others: see link to helpful post below).</p>
<p>As far as my knowledge goes, there are two main things that need to match up to make the videos reasonably playable after concatenation:</p>
<ul>
<li>The video timebase</li>
<li>The audio sampling frequency</li>
</ul>
<p>Before you can match those though, you need to know where your videos are starting from.  Run <code>ffprobe</code> on your videos to get the video timebase value (e.g. &quot;<em>30k tbn</em>&quot;) and the audio sample value (e.g. &quot;<em>44100 Hz</em>&quot;), by running:</p>
<pre><code>ffprobe -i yourvideo.mp4
</code></pre>
<p>Now match the timebase value of your <em>odd</em> videos (those with a minority <code>tbn</code> value) as described <a href="https://stackoverflow.com/a/56002050/1423189">in this post</a> using the <code>video_track_timescale</code> parameter of <code>ffmpeg</code> to match the timebase (tbn) of your other videos.  For example:</p>
<pre><code>ffmpeg -i input.mp4 -c:v libx264 -c:a copy -pix_fmt yuv420p -video_track_timescale 30000 ouput.mp4
</code></pre>
<p>Now for the audio, you can match the sampling frequency of the audio using the <code>ar</code> parameter in ffmpeg.  For example:</p>
<pre><code>ffmpeg -i input.mp4 -acodec aac -vcodec copy -ar 32000 output.mp4
</code></pre>
<p>If your run ffprobe now on your output file, your video timebase and audio sampling frequency should match your other video, and an attempt to run <code>concat</code> on your videos should now work fairly well.</p>

CC BY-SA 4.0
2022-02-11T03:42:06.960Z
Upvoted for the technically correct answer but this approach - pre-encoding the inputs before running them through the concat demuxer - loses the main benefit of using the concat demuxer, which is to avoid another re-encode by using `-c copy`. If willing to re-encode anyway you may as well just the `concat` filter, which doesn't require that inputs have the same TBN/frame rate and is just one simple command.
Hashim Aziz
CC BY-SA 4.0
2021-09-20T03:27:55.853Z
2021-09-20T03:27:55.853Z
schulwitz
<p>When I use ffmpeg to remux some recorded video (can be TS, MP4 or MKV) and get the non monotonous dts in output stream - timestamps etc etc error, the resulting video either appears to have audio only or plays jerkily. The only way I have found of reliably dealing with this is to use AviDemux. With Copy settings for both audio and video and selecting MP4V2 Muxer it is possible,, under the Configure option to select Optimize For Streaming. The resulting MP4 file can now be used in ffmpeg without generating error messages. Trust this is of use.</p>

CC BY-SA 3.0
2016-01-11T16:26:23.927Z
2016-01-11T16:26:23.927Z
gjdgjd
<h1>Using the latest <code>ffmpeg</code></h1>

<p>General users should always use <code>ffmpeg</code> from the current git master branch (the latest code available):</p>

<ul>
<li>When encountering an issue the first thing to do is check to see if you are using a build from git master.</li>
<li>It is considered stable.</li>
<li>It will have more bug fixes and features.</li>
<li><a href="http://git.videolan.org/?p=ffmpeg.git;a=shortlog">FFmpeg development is very active</a>.</li>
<li>If you want to get support from official help resources you must use git master.</li>
<li>Releases are for distributors.</li>
</ul>

<p>See the <a href="https://ffmpeg.org/download.html">FFmpeg Download</a> page for various options, or refer to <a href="https://trac.ffmpeg.org/wiki/CompilationGuide">FFmpeg Wiki: Compile Guides</a>.</p>

<h2>Other stuff</h2>

<ul>
<li><p>In your command with <code>drawbox</code> you can <a href="https://ffmpeg.org/ffmpeg.html#Stream-copy">steam copy</a> the audio with <code>-c:a copy</code> instead of re-encoding it.</p></li>
<li><p>When using <code>-ss</code>, <code>-to</code> only works as expected if <code>-ss</code> is used as an output option.</p></li>
</ul>

CC BY-SA 3.0
2015-05-04T04:54:31.727Z
Thank you very much, It does work better & faster.
Can you please check this one too http://video.stackexchange.com/questions/15477/can-i-run-this-in-one-command-line-ffmpeg  I'm just curious if it can be simplified.
whitesiroi
CC BY-SA 3.0
2015-05-04T07:12:10.300Z
@whitesiroi Sure. Answered, although it appears I made a commenter to that question unhappy.
llogan
CC BY-SA 3.0
2015-05-04T07:26:53.087Z
Sorry for that.
whitesiroi
CC BY-SA 3.0
2015-05-04T03:28:49.123Z
2015-05-04T03:28:49.123Z
llogan
<p>After running this command <code>ffmpeg -f concat -i mylist.txt -c copy output.mp4</code> - I'm getting corrupted <code>output.mp4</code> file and this message:</p>

<pre><code>ffmpeg -f concat -i mylist.txt -c copy output.mp4
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, concat, from 'mylist.txt':
  Duration: N/A, start: 0.000000, bitrate: 829 kb/s
    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1440x900, 701 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf56.25.101
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1440x900, q=2-31, 701 kb/s, 30 fps, 30 tbr, 15360 tbn, 15360 tbc
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 128 kb/s
Stream mapping:
  Stream #0:0 -&gt; #0:0 (copy)
  Stream #0:1 -&gt; #0:1 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x7f897a01bc00] Non-monotonous DTS in output stream 0:0; previous: 598061, current: 467644; changing to 598062. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7f897a01bc00] Non-monotonous DTS in output stream 0:0; previous: 598062, current: 468044; changing to 598063. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7f897a01bc00] Non-monotonous DTS in output stream 0:0; previous: 598063, current: 468444; changing to 598064. This may result in incorrect timestamps in the output file.
...
[mp4 @ 0x7f897a01bc00] Non-monotonous DTS in output stream 0:0; previous: 598362, current: 588044; changing to 598363. This may result in incorrect timestamps in the output file.
frame= 1472 fps=0.0 q=-1.0 Lsize=    5825kB time=00:00:49.04 bitrate= 973.0kbits/s
video:4903kB audio:877kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.776358%
</code></pre>

<p>Content of <code>mylist.txt</code></p>

<pre><code>file 'cut.mp4'
file 'cut2.mp4'
</code></pre>

<p>cut.mp4 output from ffmpeg:</p>

<pre><code>ffmpeg -i cut.mp4
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'cut.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:00:39.04, start: 0.036281, bitrate: 837 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1440x900, 701 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
</code></pre>

<p>cut2.mp4 output from ffmpeg:</p>

<pre><code>ffmpeg -i cut2.mp4
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'cut2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:00:10.07, start: 0.000000, bitrate: 1498 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1440x900, 1271 kb/s, 30 fps, 30 tbr, 12k tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 218 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
</code></pre>

<p><code>cut.mp4</code> I got by this command <code>ffmpeg -ss 00:00:11 -i myfile.mp4 -to 00:00:39 -vf 'drawbox= : x=0 : y=0 : color=invert' cut.mp4</code></p>

<p><code>cut2.mp4</code> I got by this command <code>ffmpeg -ss 00:00:00 -i myfile.mp4 -to 00:00:10 -c copy cut2.mp4</code></p>

<p>I searched a lot - didn't find any solution, maybe, someone can help me out  with this one.</p>

<p><code>output.mp4</code> is playable, but looks weird.</p>

<p><img src="https://i.sstatic.net/qLCHA.jpg" alt="enter image description here"></p>

CC BY-SA 3.0
2015-05-02T16:47:22.950Z
Can you provide both input files so I can perform tests?
llogan
CC BY-SA 3.0
2015-05-03T10:28:41.287Z
@LordNeckbeard yes, I sent it to you, thank you very much.
whitesiroi
CC BY-SA 3.0
2015-05-03T18:14:59.643Z
I can't seem to duplicate the exact issue. I'm using the most recent static build available from [tessus](http://evermeet.cx/ffmpeg/). The sample files seem to be different than your screenshot, but it appears to be working fine in VLC and QuickTime, except seeking seems messed up. I tested on an OS X machine because that looks like what you're using.
llogan
CC BY-SA 3.0
2015-05-04T02:22:45.963Z
@LordNeckbeard Thank you very much, yes with this version ffmpeg version N-71996-g372aa07-tessus  it does work great. Thank you.
whitesiroi
CC BY-SA 4.0
2019-09-21T23:18:57.530Z
tl;dr; remove `-c copy` to allow re-encoding or use `-c:a copy` only.  Then concat step can still use `-c copy` since all videos already re-encoded. Note that some videos with this warning still looks ok after concat and so `-c copy` is fine.
林果皞
<video><ffmpeg>
Non-Monotonous DTS on concat (ffmpeg)
whitesiroi
# Non-Monotonous DTS on concat (ffmpeg)

(Asked by: username_0 on 2015-05-02)

After running this command ffmpeg -f concat -i mylist.txt -c copy output.mp4 - I'm getting corrupted output.mp4 file and this message:
ffmpeg -f concat -i mylist.txt -c copy output.mp4
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, concat, from 'mylist.txt':
  Duration: N/A, start: 0.000000, bitrate: 829 kb/s
    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1440x900, 701 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf56.25.101
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1440x900, q=2-31, 701 kb/s, 30 fps, 30 tbr, 15360 tbn, 15360 tbc
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x7f897a01bc00] Non-monotonous DTS in output stream 0:0; previous: 598061, current: 467644; changing to 598062. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7f897a01bc00] Non-monotonous DTS in output stream 0:0; previous: 598062, current: 468044; changing to 598063. This may result in incorrect timestamps in the output file.
[mp4 @ 0x7f897a01bc00] Non-monotonous DTS in output stream 0:0; previous: 598063, current: 468444; changing to 598064. This may result in incorrect timestamps in the output file.
...
[mp4 @ 0x7f897a01bc00] Non-monotonous DTS in output stream 0:0; previous: 598362, current: 588044; changing to 598363. This may result in incorrect timestamps in the output file.
frame= 1472 fps=0.0 q=-1.0 Lsize=    5825kB time=00:00:49.04 bitrate= 973.0kbits/s
video:4903kB audio:877kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.776358%

Content of mylist.txt
file 'cut.mp4'
file 'cut2.mp4'

cut.mp4 output from ffmpeg:
ffmpeg -i cut.mp4
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'cut.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:00:39.04, start: 0.036281, bitrate: 837 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1440x900, 701 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

cut2.mp4 output from ffmpeg:
ffmpeg -i cut2.mp4
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'cut2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:00:10.07, start: 0.000000, bitrate: 1498 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1440x900, 1271 kb/s, 30 fps, 30 tbr, 12k tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 218 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

cut.mp4 I got by this command ffmpeg -ss 00:00:11 -i myfile.mp4 -to 00:00:39 -vf 'drawbox= : x=0 : y=0 : color=invert' cut.mp4
cut2.mp4 I got by this command ffmpeg -ss 00:00:00 -i myfile.mp4 -to 00:00:10 -c copy cut2.mp4
I searched a lot - didn't find any solution, maybe, someone can help me out  with this one.
output.mp4 is playable, but looks weird.

**Tags:** video, ffmpeg

> **Comments:**
> **username_1**: Can you provide both input files so I can perform tests?  
> **username_0**: @LordNeckbeard yes, I sent it to you, thank you very much.  
> **username_1**: I can't seem to duplicate the exact issue. I'm using the most recent static build available from [tessus](http://evermeet.cx/ffmpeg/). The sample files seem to be different than your screenshot, but it appears to be working fine in VLC and QuickTime, except seeking seems messed up. I tested on an OS X machine because that looks like what you're using.  
> **username_0**: @LordNeckbeard Thank you very much, yes with this version ffmpeg version N-71996-g372aa07-tessus  it does work great. Thank you.  
> **username_2**: tl;dr; remove `-c copy` to allow re-encoding or use `-c:a copy` only.  Then concat step can still use `-c copy` since all videos already re-encoded. Note that some videos with this warning still looks ok after concat and so `-c copy` is fine.  

---

## 6 answers

### Answer by username_1 on 2015-05-04. Score: 11 | Accepted answer

# Using the latest `ffmpeg`

General users should always use `ffmpeg` from the current git master branch (the latest code available):

* When encountering an issue the first thing to do is check to see if you are using a build from git master.
* It is considered stable.
* It will have more bug fixes and features.
* [FFmpeg development is very active](http://git.videolan.org/?p=ffmpeg.git;a=shortlog).
* If you want to get support from official help resources you must use git master.
* Releases are for distributors.

See the [FFmpeg Download](https://ffmpeg.org/download.html) page for various options, or refer to [FFmpeg Wiki: Compile Guides](https://trac.ffmpeg.org/wiki/CompilationGuide).

## Other stuff

* In your command with `drawbox` you can [steam copy](https://ffmpeg.org/ffmpeg.html#Stream-copy) the audio with `-c:a copy` instead of re-encoding it.
* When using `-ss`, `-to` only works as expected if `-ss` is used as an output option.

> **Comments:**
> **username_0**: Thank you very much, It does work better & faster. Can you please check this one too http://video.stackexchange.com/questions/15477/can-i-run-this-in-one-command-line-ffmpeg  I'm just curious if it can be simplified.  
> **username_1**: @username_0 Sure. Answered, although it appears I made a commenter to that question unhappy.  
> **username_0**: Sorry for that.  

---

### Answer by username_3 on 2017-12-01. Score: 4

As per https://trac.ffmpeg.org/wiki/Concatenate
I had this same issue.  I'm running ffmpeg version 2.6.3 on a mac.  I converted my source clips to the .MTS format with an added tag of -q 0, updated the extensions in the text file and set my output file to a .MTS when I ran the concat command in ffmpeg.  It worked like a charm.  Here is my workflow.
ffmpeg -i clip-1.MOV -q 0 clip-1.MTS

ffmpeg -i clip-2.MOV -q 0 clip-2.MTS

updated the text file (mylist.txt) to read:
file clip-1.MTS
file clip-2.MTS

then ran the concat command as follows:
ffmpeg -f concat -i mylist.txt -c copy output.MTS

Worked for me! You can convert the final output.MTS to whatever format you need.

> **Comments:**
> **username_4**: is this protocol lossless?  
> **username_5**: No, the first command converts to MPEG-2 which doesn't have a lossless mode.  

---

### Answer by username_7 on 2019-01-08. Score: 3

Based on Duncan's really helpful answer:
for f in *.mp4; do ffmpeg -i ${f} -q 0 "${f%.*}.mts"; done

Then this:
ffmpeg -f concat -safe 0 -i <(for f in *.mts; do echo "file '$PWD/${f}'"; done) -c copy All.mts

Or if videos are all the same format:
ffmpeg -f concat -safe 0 -i <(find . -name '*.mp4' -printf "file '$PWD/%p'\n" | sort) -c copy all.mp4

> **Comments:**
> **username_8**: That final command should search for the `.mts` files made in step one, not the original mp4s. So: `ffmpeg -f concat -safe 0 -i <(find . -name '*.mts' -printf "file '$PWD/%p'\n" | sort) -c copy all.mp4`  

---

### Answer by username_9 on 2021-09-20. Score: 3

Ok, here's an answer that has worked well for me (as well as others: see link to helpful post below).
As far as my knowledge goes, there are two main things that need to match up to make the videos reasonably playable after concatenation:

The video timebase
The audio sampling frequency

Before you can match those though, you need to know where your videos are starting from.  Run ffprobe on your videos to get the video timebase value (e.g. "30k tbn") and the audio sample value (e.g. "44100 Hz"), by running:
ffprobe -i yourvideo.mp4

Now match the timebase value of your odd videos (those with a minority tbn value) as described in this post using the video_track_timescale parameter of ffmpeg to match the timebase (tbn) of your other videos.  For example:
ffmpeg -i input.mp4 -c:v libx264 -c:a copy -pix_fmt yuv420p -video_track_timescale 30000 ouput.mp4

Now for the audio, you can match the sampling frequency of the audio using the ar parameter in ffmpeg.  For example:
ffmpeg -i input.mp4 -acodec aac -vcodec copy -ar 32000 output.mp4

If your run ffprobe now on your output file, your video timebase and audio sampling frequency should match your other video, and an attempt to run concat on your videos should now work fairly well.

> **Comments:**
> **username_10**: Upvoted for the technically correct answer but this approach - pre-encoding the inputs before running them through the concat demuxer - loses the main benefit of using the concat demuxer, which is to avoid another re-encode by using `-c copy`. If willing to re-encode anyway you may as well just the `concat` filter, which doesn't require that inputs have the same TBN/frame rate and is just one simple command.  

---

### Answer by username_6 on 2016-08-07. Score: 2

I got similar errors, and the audio in my output videos was sometimes out of sync and sometimes missing completely, but I ended up using mkvmerge from mkvtoolnix instead.
My input videos had been encoded with different settings and they had different dimensions, so I first resized and re-encoded them using ffmpeg:
for f in *.mp4;do w=1280;h=720;ffmpeg -i $f -filter:v "scale=iw*min($w/iw\,$h/ih):ih*min($w/iw\,$h/ih),pad=$w:$h:($w-iw*min($w/iw\,$h/ih))/2:($h-ih*min($w/iw\,$h/ih))/2" -c:v libx264 -crf 22 -preset slow -pix_fmt yuv420p -c:a libfdk_aac -vbr 3 -ac 2 -ar 44100 ${f%mp4}mkv;done
Some of my input videos didn't have an audio channel, so I used a command like this to add a silent audio channel to them:
for f in *.mkv;do ffprobe $f|&grep -q '1: Audio'||ffmpeg -i $f -f lavfi -i anullsrc -c:a libfdk_aac -shortest -c:v copy temp-$f;mv {temp-,}$f;done
After that I concatenated the videos:
mkvmerge -o /tmp/output.mkv $(printf %s\\n *.mkv|sed '1!s/^/+/')

If your input files have the same dimensions, the same number of audio channels, the same audio sample rate, and so on, you can use just mkvmerge to concatenate the files losslessly. The input files for mkvmerge can also have an MP4 container but the output file will have an MKV container even if its filename extension is specified as .mp4. You can run ffmpeg -i output.mkv -c copy output.mp4 to change the container.
mkvmerge has a syntax like mkvmerge -o output.mkv file1.mkv + file2.mkv + file3.mkv, where mkvmerge -o output.mkv file1.mkv +file2.mkv +file3.mkv is also accepted.


---

### Answer by username_11 on 2016-01-11. Score: 1

When I use ffmpeg to remux some recorded video (can be TS, MP4 or MKV) and get the non monotonous dts in output stream - timestamps etc etc error, the resulting video either appears to have audio only or plays jerkily. The only way I have found of reliably dealing with this is to use AviDemux. With Copy settings for both audio and video and selecting MP4V2 Muxer it is possible,, under the Configure option to select Optimize For Streaming. The resulting MP4 file can now be used in ffmpeg without generating error messages. Trust this is of use.


---

