Commit 54fa1968fe for ffmpeg

commit 54fa1968fe5d37d7d3facc4237995fdd3a20254b
Author: Kacper Michajłow <kasper93@gmail.com>
Date:   Mon Nov 2 05:33:16 2026 +0100

    avformat/mov: read a zero last edit duration as the track duration

    ISO/IEC 14496-12:2026 8.6.6.1 allows the last edit to be a non-empty
    entry with a duration of 0, which readers shall interpret as the
    accumulated duration of all samples. mov_fix_index() took the zero
    literally, discarded every sample and left such tracks without frames.
    The standard states this for fragmented movies, but a literal zero
    selects nothing in any movie, and files flattened from fragmented
    movies by other muxers keep the edit.

    Fixes: https://trac.ffmpeg.org/ticket/6138
    Fixes: https://trac.ffmpeg.org/ticket/7123
    Fixes: https://github.com/mpv-player/mpv/issues/14167
    Fixes: https://github.com/mpv-player/mpv/issues/18742
    Signed-off-by: Kacper Michajłow <kasper93@gmail.com>

diff --git a/libavformat/mov.c b/libavformat/mov.c
index bf87794e66..8492b27261 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4798,6 +4798,12 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
         av_log(mov->fc, AV_LOG_DEBUG, "Processing st: %d, edit list %"PRId64" - media time: %"PRId64", duration: %"PRId64"\n",
                st->index, edit_list_index, edit_list_media_time, edit_list_duration);
         edit_list_index++;
+        // The last edit may have a zero duration, which stands for the
+        // accumulated duration of all samples (ISO/IEC 14496-12:2026 8.6.6.1).
+        // Specified for fragmented movies, but files flattened from them keep it.
+        if (!msc->elst_data[edit_list_index - 1].duration &&
+            edit_list_media_time >= 0 && edit_list_index == msc->elst_count)
+            edit_list_duration = av_clip64(msc->track_end, 0, INT64_MAX - edit_list_media_time);
         edit_list_dts_counter = edit_list_dts_entry_end;
         edit_list_dts_entry_end = av_sat_add64(edit_list_dts_entry_end, edit_list_duration);
         if (edit_list_dts_entry_end == INT64_MAX) {