PR #23203 opened by Zhao Zhili (quink) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23203 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23203.patch
avformat_index_get_entry_from_timestamp() was called with the file position passed as wanted_timestamp, so the lookup was meaningless. Walk the index by pos and, while at it, take the timestamp from the matched entry. **This patch hasn't been tested because I don't have a sample.** >From 3a971b863fa4f101f169ef39c3fa7b5e08793efd Mon Sep 17 00:00:00 2001 From: Zhao Zhili <[email protected]> Date: Sat, 23 May 2026 02:25:41 +0800 Subject: [PATCH 1/2] avformat/mods: fix keyframe flagging in read_packet avformat_index_get_entry_from_timestamp() was called with the file position passed as wanted_timestamp, so the lookup was meaningless. Walk the index by pos and, while at it, take the timestamp from the matched entry. --- libavformat/mods.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libavformat/mods.c b/libavformat/mods.c index 7949bcd657..86cd76a8d1 100644 --- a/libavformat/mods.c +++ b/libavformat/mods.c @@ -101,10 +101,10 @@ static int mods_read_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; MODSDemuxContext *ctx = s->priv_data; + AVStream *st = s->streams[0]; unsigned size; int64_t pos; int ret; - const AVIndexEntry *e; if (avio_feof(pb)) return AVERROR_EOF; @@ -119,9 +119,14 @@ static int mods_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->pos = pos; pkt->stream_index = 0; - e = avformat_index_get_entry_from_timestamp(s->streams[0], pos, 0); - if (e) - pkt->flags |= AV_PKT_FLAG_KEY; + for (int i = 0; i < avformat_index_get_entries_count(st); i++) { + const AVIndexEntry *e = avformat_index_get_entry(st, i); + if (e && e->pos == pos) { + pkt->flags |= AV_PKT_FLAG_KEY; + pkt->pts = pkt->dts = e->timestamp; + break; + } + } return ret; } -- 2.52.0 >From 4db0bd01eb37a5dca96c7f953d78d9eae82c0709 Mon Sep 17 00:00:00 2001 From: Zhao Zhili <[email protected]> Date: Sat, 23 May 2026 02:20:20 +0800 Subject: [PATCH 2/2] avformat/mods: bail out on av_get_packet() failure --- libavformat/mods.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/mods.c b/libavformat/mods.c index 86cd76a8d1..e11e14a9ee 100644 --- a/libavformat/mods.c +++ b/libavformat/mods.c @@ -116,6 +116,8 @@ static int mods_read_packet(AVFormatContext *s, AVPacket *pkt) size = avio_rl32(pb) >> 14; ret = av_get_packet(pb, pkt, size); + if (ret < 0) + return ret; pkt->pos = pos; pkt->stream_index = 0; -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
