title: How to concat multiple video files which have different stream order with FFmpeg?
body: <p>I have 3 video files with following info:</p>
  
  <pre><code>Input #0, mpegts, from '01.ts':
    Duration: 00:00:06.08, start: 0.000000, bitrate: 931 kb/s
    Program 1
      Stream #0:0[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 65 kb/s
      Stream #0:1[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
  
  
  Input #0, mpegts, from '02.ts':
    Duration: 00:00:06.06, start: 6.016000, bitrate: 872 kb/s
      Stream #0:0[0x102]: Video: h264 (High), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
      Stream #0:1[0x101]: Audio: aac (LC), 48000 Hz, stereo, fltp, 66 kb/s
  
  
  Input #0, mpegts, from '03.ts':
    Duration: 00:00:06.07, start: 12.010667, bitrate: 822 kb/s
      Stream #0:0[0x102]: Video: h264 (High), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
      Stream #0:1[0x101]: Audio: aac (LC), 48000 Hz, stereo, fltp, 69 kb/s
  </code></pre>
  
  <p>Most of them are the same, but somehow 01.ts has different stream order with the other two. My question is, how to concat them? I've tried to put them in a txt file and concat:</p>
  
  <pre><code>-f concat -safe 0 -i video_file.txt -c copy -bsf:a aac_adtstoasc output.mp4
  </code></pre>
  
  <p>But it's not working. Error message is:</p>
  
  <pre><code>Error parsing ADTS frame header!
  Error applying bitstream filters to an output packet for stream #0:1.
  </code></pre>
  
  <p>And what if I have hundreds of video files that may have diffrent stream order like this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p><a href="https://stackoverflow.com/a/54485169/927622">aergistal's answer</a> is correct, but I have another problem: in another collection of videos, the stream ids are different, as following:</p>
  
  <pre><code>Input #0, mpegts, from 'another1.ts':
    Duration: 00:00:08.04, start: 17.401333, bitrate: 284 kb/s
    Program 1
      Metadata:
        service_name    : Service01
        service_provider: FFmpeg
      Stream #0:0[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(progressive), 352x288 [SAR 16:11 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
      Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 124 kb/s
  
  
  Input #0, mpegts, from 'another2.ts':
    Duration: 00:00:08.04, start: 33.401333, bitrate: 300 kb/s
    Program 1
      Metadata:
        service_name    : Service01
        service_provider: FFmpeg
      Stream #0:0[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(progressive), 352x288 [SAR 16:11 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
      Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 145 kb/s
  </code></pre>
  
  <p>Is there a way to set the <code>exact_stream_id</code> automatically instead of check it everytime?</p>