PR #26400 opened by James Almer (jamrial)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26400
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26400.patch

ISO/IEC 14496-12 defines them as unsigned 32 bit integers.
Store them as int64_t to keep allowing negative values to signal missing id.

Fixes issue #26393


>From 427cbe7e802700cf014c984e72f5c7cc8d94bf21 Mon Sep 17 00:00:00 2001
From: James Almer <[email protected]>
Date: Fri, 27 Nov 2026 11:06:09 -0300
Subject: [PATCH] avformat/mov: don't store track ids as signed 32 bit integers

ISO/IEC 14496-12 defines them as unsigned 32 bit integers.
Store them as int64_t to keep allowing negative values to signal missing id.

Fixes issue #26393

Signed-off-by: James Almer <[email protected]>
---
 libavformat/isom.h |  4 ++--
 libavformat/mov.c  | 11 ++++++-----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 5866d39106d..4cc89074d36 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -161,7 +161,7 @@ typedef struct MOVEncryptionIndex {
 } MOVEncryptionIndex;
 
 typedef struct MOVFragmentStreamInfo {
-    int id;
+    uint32_t id;
     int64_t sidx_pts;
     int64_t first_tfra_pts;
     int64_t tfdt_dts;
@@ -198,7 +198,7 @@ typedef struct MOVStreamContext {
     AVIOContext *pb;
     int refcount;
     int pb_is_copied;
-    int id;               ///< AVStream id
+    int64_t id;           ///< AVStream id
     int ffindex;          ///< AVStream index
     int next_chunk;
     unsigned int chunk_count;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 14e8dbc9bc7..0d7a7ccc153 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1799,7 +1799,7 @@ static int mov_read_moov(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 static MOVFragmentStreamInfo * get_frag_stream_info(
     MOVFragmentIndex *frag_index,
     int index,
-    int id)
+    int64_t id)
 {
     int i;
     MOVFragmentIndexItem * item;
@@ -4062,7 +4062,7 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
     if (!duration && sc->stts_count &&
             st->codecpar->codec_type == AVMEDIA_TYPE_DATA) {
         av_log(c->fc, AV_LOG_WARNING,
-               "All samples in data stream index:id [%d:%d] have zero "
+               "All samples in data stream index:id [%d:%"PRId64"] have zero "
                "duration, stream set to be discarded by default. Override "
                "using AVStream->discard or -discard for ffmpeg command.\n",
                st->index, sc->id);
@@ -5727,6 +5727,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
     sc->ffindex = st->index;
     c->trak_index = st->index;
     sc->refcount = 1;
+    sc->id = -1;
 
     if ((ret = mov_read_default(c, pb, atom)) < 0)
         return ret;
@@ -6146,8 +6147,8 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
         avio_rb32(pb); /* creation time */
         avio_rb32(pb); /* modification time */
     }
-    st->id = (int)avio_rb32(pb); /* track id (NOT 0 !)*/
-    sc->id = st->id;
+    sc->id = avio_rb32(pb); /* track id (NOT 0 !)*/
+    st->id = (int)sc->id;
     avio_rb32(pb); /* reserved */
 
     /* highlevel (considering edits) duration in movie timebase */
@@ -9077,7 +9078,7 @@ static int cenc_decrypt(MOVContext *c, MOVStreamContext 
*sc, AVEncryptionInfo *s
     }
 }
 
-static MOVFragmentStreamInfo *get_frag_stream_info_from_pkt(MOVFragmentIndex 
*frag_index, AVPacket *pkt, int id)
+static MOVFragmentStreamInfo *get_frag_stream_info_from_pkt(MOVFragmentIndex 
*frag_index, AVPacket *pkt, int64_t id)
 {
     int current = frag_index->current;
 
-- 
2.54.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to