Answers.Body: <p>It's using a counter! To get it to be stream #5, map 5 streams before it :)</p>
  
  <p>That said, mp4box will allow you to set a custom track ID.</p>
  
  <pre><code>mp4box -set-track-id 1:5 file.mp4
  </code></pre>
  
  <p>This changes existing track with ID 1 to 5. Use <code>mp4box -info file.mp4</code> to get existing IDs.</p>
  
  <p>However, this will still show up as stream <code>0</code> in ffmpeg. But mediainfo and mp4box will show it as having ID 5.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-04T23:35:31.307Z
Answers.Text: I think the command should fail(i.e. Error<5 higher than the number of total streams>) instead to fallback to various counters. Basically `-c:5` param is ignored.
Answers.UserDisplayName: mike
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-04T23:43:44.120Z
Answers.Text: Actually I have found that -c:$ID provided is not used regardless of the number of streams. Even if you just want to copy the streams in reverse order (i.e. first stream to become the 2nd and the 2nd stream to become the first) ffmpeg ignores this and writes them in the same order(first stream from input to first stream from output and same for the 2nd stream) ` ffmpeg -i "input.mkv" -y -map 0:0 -c:1 copy -map 0:1 -c:0 copy  -f mp4 x.mp4`   results in ` Stream #0:0 -> #0:0 (copy)
    Stream #0:1 -> #0:1 (copy)
  `
Answers.UserDisplayName: mike
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-05T05:11:38.383Z
Answers.Text: Sequence of streams in output is determined by order of map assignments. Stream specifiers for other options like `-c` only set the value for that output stream # for that option. So, `-map 0:1 -map 0:0` will place 2nd input stream first in the output.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-04T15:38:34.207Z
Answers.LastActivityDate: 2017-12-04T15:44:53.420Z
Answers.LastEditDate: 2017-12-04T15:44:53.420Z
Answers.UserDisplayName: Gyan
Answers.Body: <p>Its the order you pass the mappings.</p>
  <p>-map 0:3 becomes stream 0:0</p>
  <p>-map 0:1 becomes stream 0:1</p>
  <pre><code>  ffmpeg -i  2plp0.ts -map 0:3 -map 0:1 -c copy -y out.ts
  
  
  
     Stream mapping:
    Stream #0:3 -&gt; #0:0 (copy)
    Stream #0:1 -&gt; #0:1 (copy)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-24T07:25:51.837Z
Answers.LastActivityDate: 2021-09-24T07:25:51.837Z
Answers.UserDisplayName: Leroy Scandal
Body: <p>I'm trying to map specific streams to specific output indexes. The command I'm using is more complex but it can be reduced to this simple example</p>
  
  <p><code>ffmpeg -i input.mkv -y -map 0:0 -c:5 copy -f mp4 out.mp4</code></p>
  
  <p>I expected this to copy stream <code>0</code> from <code>input.mkv</code> into stream <code>5</code> of <code>out.mp4</code>. The issue is that it copies it into stream <code>0</code> (I guess it's using a counter?). Why is that and how can I force it to assign it a different index number?</p>
  
  <p><code>Stream #0:0 -&gt; #0:0 (h264 (native) -&gt; h264 (libx264))</code></p>
  
Tags: <ffmpeg>
Title: How to map streams to specific output streamIDs
UserDisplayName: mike
ThreadText: # How to map streams to specific output streamIDs
  
  (Asked by: username_0 on 2017-12-04)
  
  I'm trying to map specific streams to specific output indexes. The command I'm using is more complex but it can be reduced to this simple example
  
  `ffmpeg -i input.mkv -y -map 0:0 -c:5 copy -f mp4 out.mp4`
  
  I expected this to copy stream `0` from `input.mkv` into stream `5` of `out.mp4`. The issue is that it copies it into stream `0` (I guess it's using a counter?). Why is that and how can I force it to assign it a different index number?
  
  `Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))`
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-12-04. Score: 1 | Accepted answer
  
  It's using a counter! To get it to be stream #5, map 5 streams before it :)
  
  That said, mp4box will allow you to set a custom track ID.
  
  ```
  mp4box -set-track-id 1:5 file.mp4
  
  ```
  
  This changes existing track with ID 1 to 5. Use `mp4box -info file.mp4` to get existing IDs.
  
  However, this will still show up as stream `0` in ffmpeg. But mediainfo and mp4box will show it as having ID 5.
  
  > **Comments:**
  > **username_0**: I think the command should fail(i.e. Error<5 higher than the number of total streams>) instead to fallback to various counters. Basically `-c:5` param is ignored.  
  > **username_0**: Actually I have found that -c:$ID provided is not used regardless of the number of streams. Even if you just want to copy the streams in reverse order (i.e. first stream to become the 2nd and the 2nd stream to become the first) ffmpeg ignores this and writes them in the same order(first stream from input to first stream from output and same for the 2nd stream) ` ffmpeg -i "input.mkv" -y -map 0:0 -c:1 copy -map 0:1 -c:0 copy  -f mp4 x.mp4`   results in ` Stream #0:0 -> #0:0 (copy)   Stream #0:1 -> #0:1 (copy) `  
  > **username_1**: Sequence of streams in output is determined by order of map assignments. Stream specifiers for other options like `-c` only set the value for that output stream # for that option. So, `-map 0:1 -map 0:0` will place 2nd input stream first in the output.  
  
  ---
  
  ### Answer by username_2 on 2021-09-24. Score: 0
  
  Its the order you pass the mappings.
  
  -map 0:3 becomes stream 0:0
  
  -map 0:1 becomes stream 0:1
  
  ```
    ffmpeg -i  2plp0.ts -map 0:3 -map 0:1 -c copy -y out.ts
  
     Stream mapping:
    Stream #0:3 -> #0:0 (copy)
    Stream #0:1 -> #0:1 (copy)
  
  ```
  
  
  ---
  
  