title: Concatenate TS files with correct timestamps
body: <p>I'm trying to merge multiple ts chunk files to one single file, without any loss of quality or reencoding. The files are taken from a live stream, however I'm trying to merge them in a diffrent order and not the order they were streamed.</p>
  
  <p>Example of files:</p>
  
  <pre><code>0000000033.ts
  0000000034.ts
  0000000039.ts
  0000000044.ts
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>cat 0000000033.ts 0000000034.ts 0000000039.ts 0000000044.ts &gt;combined.ts
  </code></pre>
  
  <p>and </p>
  
  <pre><code>ffmpeg -i "concat:0000000033.ts|concat:0000000034.ts|concat:0000000039.ts|concat:0000000044.ts" -c copy -bsf:a aac_adtstoasc output.mp4
  </code></pre>
  
  <p>This kinda works, however I instead of beeing 4 seconds long it's around 15. It plays this way:</p>
  
  <pre><code>[first 2 clips]
  [5 secs pause]
  [39.ts]
  [5 secs pause]
  [44.ts]
  [done]
  </code></pre>
  
  <p>This happens to both the cat and ffmpeg combined version. So it seems the ts chunks contain timestamps from the stream that are beeing used.</p>
  
  <p>How can I fix that to make it one continous clip?</p>
  
  <p>The chunks here are more of an example, the chunks will be dynamically selected.</p>