This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 80375ca773a5009ddba29f5d73e1fbd70baadc02
Author:     Romain Beauxis <[email protected]>
AuthorDate: Wed Apr 22 21:00:52 2026 -0500
Commit:     Romain Beauxis <[email protected]>
CommitDate: Mon Jun 1 21:53:36 2026 -0500

    avformat/mpegts: update stream metadata from timed_id3 packets
    
    Set AVSTREAM_EVENT_FLAG_METADATA_UPDATED so applications can detect
    mid-stream metadata changes without inspecting packet side data.
---
 libavformat/mpegts.c              | 31 +++++++++++++++++++++++++++++++
 tests/ref/fate/ts-timed-id3-demux |  2 +-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 21fdbe6b17..486b4a2176 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -43,6 +43,7 @@
 #include "demux.h"
 #include "mpeg.h"
 #include "isom.h"
+#include "id3v2.h"
 #if CONFIG_ICONV
 #include <iconv.h>
 #endif
@@ -1029,6 +1030,30 @@ static void new_data_packet(const uint8_t *buffer, int 
len, AVPacket *pkt)
     pkt->size = len;
 }
 
+static int timed_id3_update_metadata(AVStream *s, AVPacket *pkt)
+{
+    FFIOContext id3_buf;
+    ID3v2ExtraMeta *extra_meta = NULL;
+    AVDictionary *metadata = NULL;
+    int ret = 0;
+
+    ffio_init_read_context(&id3_buf, pkt->data, pkt->size);
+    ff_id3v2_read_dict(&id3_buf.pub, &metadata, ID3v2_DEFAULT_MAGIC, 
&extra_meta);
+    ret = ff_id3v2_parse_priv_dict(&metadata, extra_meta);
+    ff_id3v2_free_extra_meta(&extra_meta);
+
+    if (ret < 0 || !av_dict_count(metadata))
+        goto end;
+
+    ret = av_dict_copy(&s->metadata, metadata, 0);
+    if (ret == 0)
+        s->event_flags |= AVSTREAM_EVENT_FLAG_METADATA_UPDATED;
+
+end:
+    av_dict_free(&metadata);
+    return ret;
+}
+
 static int new_pes_packet(PESContext *pes, AVPacket *pkt)
 {
     uint8_t *sd;
@@ -1083,6 +1108,12 @@ static int new_pes_packet(PESContext *pes, AVPacket *pkt)
         return AVERROR(ENOMEM);
     *sd = pes->stream_id;
 
+    if (pes->st->codecpar->codec_id == AV_CODEC_ID_TIMED_ID3) {
+        int ret = timed_id3_update_metadata(pes->st, pkt);
+        if (ret < 0)
+            return ret;
+    }
+
     return 0;
 }
 
diff --git a/tests/ref/fate/ts-timed-id3-demux 
b/tests/ref/fate/ts-timed-id3-demux
index 3de1ca2990..3e1f13d79c 100644
--- a/tests/ref/fate/ts-timed-id3-demux
+++ b/tests/ref/fate/ts-timed-id3-demux
@@ -1,4 +1,4 @@
 
packet|codec_type=data|stream_index=0|pts=126000|pts_time=1.400000|dts=126000|dts_time=1.400000|duration=N/A|duration_time=N/A|size=26|pos=564|flags=K__|data_hash=CRC32:469f474b|side_datum/mpegts_stream_id:side_data_type=MPEGTS
 Stream ID|side_datum/mpegts_stream_id:id=189
 
packet|codec_type=data|stream_index=0|pts=577350|pts_time=6.415000|dts=577350|dts_time=6.415000|duration=N/A|duration_time=N/A|size=26|pos=1316|flags=K__|data_hash=CRC32:469f474b|side_datum/mpegts_stream_id:side_data_type=MPEGTS
 Stream ID|side_datum/mpegts_stream_id:id=189
-stream|index=0|codec_name=timed_id3|profile=unknown|codec_type=data|codec_tag_string=ID3
 
|codec_tag=0x20334449|ts_id=1|ts_packetsize=188|id=0x100|r_frame_rate=0/0|avg_frame_rate=0/0|time_base=1/90000|start_pts=126000|start_time=1.400000|duration_ts=451350|duration=5.015000|bit_rate=N/A|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=N/A|nb_read_packets=2|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposi
 [...]
+stream|index=0|codec_name=timed_id3|profile=unknown|codec_type=data|codec_tag_string=ID3
 
|codec_tag=0x20334449|ts_id=1|ts_packetsize=188|id=0x100|r_frame_rate=0/0|avg_frame_rate=0/0|time_base=1/90000|start_pts=126000|start_time=1.400000|duration_ts=451350|duration=5.015000|bit_rate=N/A|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=N/A|nb_read_packets=2|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposi
 [...]
 
format|filename=id3.ts|nb_streams=1|nb_programs=1|nb_stream_groups=0|format_name=mpegts|start_time=1.400000|duration=5.015000|size=1504|bit_rate=2399|probe_score=2

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

Reply via email to