PR #26208 opened by Derek Buitenhuis (dwbuiten) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26208 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26208.patch
If an edit list contains a media time that falls between the last non-displayable frame and first displayable frame, previously, the demuxer would output a full GOP that is not needed to actually decode the stream. To fix this, we do a clean up pass to find the nearest relative keyframe to it (using at most one GOP). AI was used review this patch before sending (hence the check for `INT64_MAX`). >From df0866fc930a3455497c0be0390424433f0eebef Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis <[email protected]> Date: Thu, 19 Nov 2026 19:28:15 +0000 Subject: [PATCH] avformat/mov: Take non-frame-timed edit list boundaires into account when outputting packets If an edit list contains a media time that falls between the last non-displayable frame and first displayable frame, previously, the demuxer would output a full GOP that is not needed to actually decode the stream. To fix this, we do a clean up pass to find the nearest relative keyframe to it (using at most one GOP). Signed-off-by: Derek Buitenhuis <[email protected]> --- libavformat/mov.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 85936bf8252..02a43facdf5 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -4731,6 +4731,33 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) tts_index_old = 0; tts_sample_old = 0; } + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + // If media_time falls between two samples, searching for a keyframe with a + // PTS smaller than that pulls in the entire preceding GOP, all of which is + // marked as discard. Check relative to the first shown frame. + int64_t first_pts = INT64_MAX; + int64_t new_index, new_tts_index = tts_index_old, new_tts_sample = tts_sample_old; + + for (int64_t i = index; i < nb_old && e_old[i].timestamp < first_pts; i++) { + int64_t pts = e_old[i].timestamp + msc->dts_shift; + if (tts_data_old && i < tts_count_old) + pts += tts_data_old[i].offset; + if (pts >= edit_list_media_time && pts < first_pts) + first_pts = pts; + } + + if (first_pts != INT64_MAX && first_pts > edit_list_media_time && + first_pts - edit_list_media_time < edit_list_duration && + find_prev_closest_index(st, e_old, nb_old, tts_data_old, tts_count_old, first_pts, 0, + &new_index, &new_tts_index, &new_tts_sample) >= 0 && + new_index > index) { + av_log(mov->fc, AV_LOG_DEBUG, + "st: %d edit list %"PRId64" starting at key frame %"PRId64" instead of %"PRId64" (first pts: %"PRId64")\n", + st->index, edit_list_index, new_index, index, first_pts); + index = new_index; + tts_index_old = new_tts_index; + tts_sample_old = new_tts_sample; + } } current = e_old + index; edit_list_start_tts_sample = tts_sample_old; -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
