[PR] avformat/mov: Use sequential IDs for stream groups (PR #24256)

vigneshvg via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <[email protected]>
PR #24256 opened by vigneshvg
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24256
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24256.patch

Previously, stream group IDs were assigned using various
source identifiers such as stream IDs, item IDs, or IAMF
element IDs. This could lead to collisions across
different stream group types.

Use next_stream_group_id in MOVContext to assign
sequentially incrementing IDs starting from 1 for all
stream groups created in the MOV demuxer.

Signed-off-by: Vignesh Venkat <[email protected]>


>From bf58587bf4bfb4843fb3f6dab23201de213fea7c Mon Sep 17 00:00:00 2001
From: Vignesh Venkat <[email protected]>
Date: Wed, 19 Aug 2026 09:13:07 -0700
Subject: [PATCH] avformat/mov: Use sequential IDs for stream groups

Previously, stream group IDs were assigned using various
source identifiers such as stream IDs, item IDs, or IAMF
element IDs. This could lead to collisions across
different stream group types.

Use next_stream_group_id in MOVContext to assign
sequentially incrementing IDs starting from 1 for all
stream groups created in the MOV demuxer.

Signed-off-by: Vignesh Venkat <[email protected]>
---
 libavformat/isom.h                             |  1 +
 libavformat/mov.c                              | 18 +++++++++++-------
 tests/ref/fate/mov-heic-demux-still-image-grid |  2 +-
 tests/ref/fate/mov-heic-demux-still-image-iovl |  2 +-
 .../ref/fate/mov-heic-demux-still-image-iovl-2 |  2 +-
 5 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index e02af09aaa..2d9ec892b5 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -391,6 +391,7 @@ typedef struct MOVContext {
     int interleaved_read;
     AVDictionary* decryption_keys;
     unsigned heif_icc_profile_items;
+    int next_stream_group_id;
 } MOVContext;
 
 int ff_mp4_read_descr_len(AVIOContext *pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index f53ce693f8..85da5e2cfd 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -982,7 +982,7 @@ static int mov_read_iacb(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         }
 
         av_iamf_audio_element_free(&stg->params.iamf_audio_element);
-        stg->id = audio_element->audio_element_id;
+        stg->id = ++c->next_stream_group_id;
         /* Transfer ownership */
         element = stg->params.iamf_audio_element = audio_element->element;
         audio_element->element = NULL;
@@ -1049,7 +1049,7 @@ static int mov_read_iacb(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         }
 
         av_iamf_mix_presentation_free(&stg->params.iamf_mix_presentation);
-        stg->id = mix_presentation->mix_presentation_id;
+        stg->id = ++c->next_stream_group_id;
         /* Transfer ownership */
         stg->params.iamf_mix_presentation = mix_presentation->mix;
         mix_presentation->mix = NULL;
@@ -11091,7 +11091,7 @@ static int mov_parse_tiles(AVFormatContext *s)
         if (!stg)
             return AVERROR(ENOMEM);
 
-        stg->id = grid->item->item_id;
+        stg->id = ++mov->next_stream_group_id;
         tile_grid = stg->params.tile_grid;
 
         for (int j = 0; j < grid->nb_tiles; j++) {
@@ -11285,6 +11285,7 @@ static int mov_parse_heif_items(AVFormatContext *s)
 
 static int mov_parse_tmcd_streams(AVFormatContext *s)
 {
+    MOVContext *mov = s->priv_data;
     int err;
 
     for (int i = 0; i < s->nb_streams; i++) {
@@ -11299,7 +11300,7 @@ static int mov_parse_tmcd_streams(AVFormatContext *s)
         if (!stg)
             return AVERROR(ENOMEM);
 
-        stg->id = st->id;
+        stg->id = ++mov->next_stream_group_id;
         tcr = av_dict_get(st->metadata, "timecode", NULL, 0);
 
         for (int j = 0; j < s->nb_streams; j++) {
@@ -11361,6 +11362,7 @@ static int mov_parse_cdsc_and_rndr_streams(AVFormatContext *s)
         MKTAG('r','n','d','r'),
     };
 
+    MOVContext *mov = s->priv_data;
     int err;
 
     // Don't try to add a group if there's only one track
@@ -11392,7 +11394,7 @@ static int mov_parse_cdsc_and_rndr_streams(AVFormatContext *s)
             if (!stg)
                 return AVERROR(ENOMEM);
 
-            stg->id = st_ref->id;
+            stg->id = ++mov->next_stream_group_id;
 
             err = avformat_stream_group_add_stream(stg, st_ref);
             if (err < 0)
@@ -11411,6 +11413,7 @@ static int mov_parse_cdsc_and_rndr_streams(AVFormatContext *s)
 
 static int mov_parse_lcevc_streams(AVFormatContext *s)
 {
+    MOVContext *mov = s->priv_data;
     int err;
 
     // Don't try to add a group if there's only one track
@@ -11433,7 +11436,7 @@ static int mov_parse_lcevc_streams(AVFormatContext *s)
         if (!stg)
             return AVERROR(ENOMEM);
 
-        stg->id = st->id;
+        stg->id = ++mov->next_stream_group_id;
         stg->params.layered_video->width  = st->codecpar->width;
         stg->params.layered_video->height = st->codecpar->height;
 
@@ -11465,6 +11468,7 @@ static int mov_parse_lcevc_streams(AVFormatContext *s)
 
 static int mov_parse_dovi_streams(AVFormatContext *s)
 {
+    MOVContext *mov = s->priv_data;
     int err;
 
     if (s->nb_streams <= 1)
@@ -11518,7 +11522,7 @@ static int mov_parse_dovi_streams(AVFormatContext *s)
         if (!stg)
             return AVERROR(ENOMEM);
 
-        stg->id = st->id;
+        stg->id = ++mov->next_stream_group_id;
 
         err = avformat_stream_group_add_stream(stg, st_base);
         if (err < 0)
diff --git a/tests/ref/fate/mov-heic-demux-still-image-grid b/tests/ref/fate/mov-heic-demux-still-image-grid
index f7d0b178e1..59b5964709 100644
--- a/tests/ref/fate/mov-heic-demux-still-image-grid
+++ b/tests/ref/fate/mov-heic-demux-still-image-grid
@@ -28,7 +28,7 @@
 3,          0,          0,        1,   111353, 0x26435c8c
 [STREAM_GROUP]
 index=0
-id=0x3f1
+id=0x1
 nb_streams=4
 type=Tile Grid
 [COMPONENT]
diff --git a/tests/ref/fate/mov-heic-demux-still-image-iovl b/tests/ref/fate/mov-heic-demux-still-image-iovl
index 4a90220c34..4b74d0c7bc 100644
--- a/tests/ref/fate/mov-heic-demux-still-image-iovl
+++ b/tests/ref/fate/mov-heic-demux-still-image-iovl
@@ -14,7 +14,7 @@
 1,          0,          0,        1,   112393, 0xdf2b9da0
 [STREAM_GROUP]
 index=0
-id=0x3ee
+id=0x1
 nb_streams=2
 type=Tile Grid
 [COMPONENT]
diff --git a/tests/ref/fate/mov-heic-demux-still-image-iovl-2 b/tests/ref/fate/mov-heic-demux-still-image-iovl-2
index 3ee119ff6f..db72e17b9d 100644
--- a/tests/ref/fate/mov-heic-demux-still-image-iovl-2
+++ b/tests/ref/fate/mov-heic-demux-still-image-iovl-2
@@ -7,7 +7,7 @@
 0,          0,          0,        1,   111554, 0xa0679859
 [STREAM_GROUP]
 index=0
-id=0x3eb
+id=0x1
 nb_streams=1
 type=Tile Grid
 [COMPONENT]
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.