<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>

CC BY-SA 3.0
2017-12-04T23:35:31.307Z
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.
mike
CC BY-SA 3.0
2017-12-04T23:43:44.120Z
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)
`
mike
CC BY-SA 3.0
2017-12-05T05:11:38.383Z
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.
Gyan
CC BY-SA 3.0
2017-12-04T15:38:34.207Z
2017-12-04T15:44:53.420Z
2017-12-04T15:44:53.420Z
Gyan
<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>

CC BY-SA 4.0
2021-09-24T07:25:51.837Z
2021-09-24T07:25:51.837Z
Leroy Scandal
<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>

<ffmpeg>
How to map streams to specific output streamIDs
mike
# 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)


---

