title: How to concatenate two MP4 files using FFmpeg?
body: <p>I'm trying to concatenate two mp4 files using ffmpeg.  I need this to be an automatic process hence why I chose ffmpeg.  I'm converting the two files into <code>.ts</code> files and then concatenating them and then trying to encode that concatenated <code>.ts</code> file.  The files are <code>h264</code> and <code>aac</code> encoded and I'm hoping to keep the quality the same or as close to original as possible.</p>
  <pre><code>ffmpeg -i part1.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy part1.ts
  ffmpeg -i part2.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy part2.ts
  cat part1.ts part2.ts &gt; parts.ts
  ffmpeg -y -i parts.ts -acodec copy -ar 44100 -ab 96k -coder ac -vbsf h264_mp4toannexb parts.mp4
  </code></pre>
  <p>Unfortunately I'm getting the following error message coming back from ffmpeg during encoding:</p>
  <pre><code>[h264 @ 0x1012600]sps_id out of range
  [h264 @ 0x1012600]non-existing SPS 0 referenced in buffering period
  [h264 @ 0x1012600]sps_id out of range
  [h264 @ 0x1012600]non-existing SPS 0 referenced in buffering period
  [NULL @ 0x101d600]error, non monotone timestamps 13779431 &gt;= 13779431kbits/s    
  av_interleaved_write_frame(): Error while opening file
  </code></pre>
  <p>This happens about half way through encoding which makes me think that you can't concat two .ts files together and have it work.</p>