Commit 9181f3a924 for ffmpeg
commit 9181f3a92495e93c4bf0a1bcab00992ed59397d1
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Sat Oct 10 06:48:07 2026 +0200
avformat/mov: compute the time to sample position of an edit directly
find_prev_closest_index() walked the time to sample table from the
first sample up to the sample an edit starts at, for every edit of a
track with composition offsets, so the index rebuild cost
elst_count * nb_samples. An 800 kB file with 50000 edits over 200000
samples took 58 seconds to open.
Timeout Replicated through UnModified FFmpeg
Found during triage/review of OSS-Fuzz issue 476170159
Fixes: Timeout
Fixes: 6w5v8aNoJQB4/slow.mp4 / genmp4.py
Fixes: 6w5v8aNoJQB4
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2c88f65a76..9e6a57d083 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4277,17 +4277,8 @@ static int find_prev_closest_index(AVStream *st,
av_assert0(tts_index);
av_assert0(tts_sample);
// Find out the ctts_index for the found frame.
- *tts_index = 0;
+ *tts_index = FFMIN(*index, tts_count);
*tts_sample = 0;
- for (int64_t index_tts_count = 0; index_tts_count < *index; index_tts_count++) {
- if (*tts_index < tts_count) {
- (*tts_sample)++;
- if (tts_data[*tts_index].count == *tts_sample) {
- (*tts_index)++;
- *tts_sample = 0;
- }
- }
- }
while (*index >= 0 && (*tts_index) >= 0 && (*tts_index) < tts_count) {
// Find a "key frame" with PTS <= timestamp_pts (So that we can decode B-frames correctly).