In some scenarios nb_tracks isn't the same as nb_streams, so a given id may end up being used for two separate streams. e.g. when muxing an IAMF track followed by a video track, if the IAMF track consists of several streams, the video track would end up having an id of 2, which may also be used by one of the IAMF streams.
Unified · Split
| @@ -4944,11 +4944,15 @@ static int mov_setup_track_ids(MOVMuxContext *mov, AVFormatContext *s) · 4943 unmodified lines | ||
| 4944 | 4944 | mov->tracks[i].track_id = i >= mov->nb_streams ? ++next_generated_track_id : mov->tracks[i].st->id; |
| 4945 | 4945 | } |
| 4946 | 4946 | } else { |
| 4947 | + int last_track_id = 0; | |
| 4947 | 4948 | for (i = 0; i < mov->nb_tracks; i++) { |
| 4948 | 4949 | if (mov->tracks[i].entry <= 0 && !(mov->flags & FF_MOV_FLAG_FRAGMENT)) |
| 4949 | 4950 | continue; |
| 4950 | 4951 | |
| 4951 | − mov->tracks[i].track_id = i + 1; | |
| 4952 | + last_track_id = | |
| 4953 | + mov->tracks[i].track_id = (mov->tracks[i].st | |
| 4954 | + ? FFMAX(mov->tracks[i].st->index, last_track_id) | |
| 4955 | + : FFMAX((i ? mov->tracks[i - 1].track_id : i), last_track_id)) + 1; | |
| 4952 | 4956 | } |
| 4953 | 4957 | } |
| 4954 | 4958 | |