Hopefully I got the calls to mov_switch_root() right. mov_read_default() just ends up calling mov_read_moof() twice on the first moof
/Tomas
From bbcff7581177b25b03e0f53ebb4732b7f10f0616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <g...@haerdin.se> Date: Mon, 16 Dec 2024 15:25:44 +0100 Subject: [PATCH 2/6] lavf/mov: Read duration when parsing mfra Without this mov files with mfra do not have the correct duration set. Without sidx present we must read the last fragment header, which this patch does. --- libavformat/mov.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index cfcd64b7db..98a05e8411 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1800,6 +1800,8 @@ static void fix_frag_index_entries(MOVFragmentIndex *frag_index, int index, } } +static int mov_switch_root(AVFormatContext *s, int64_t target, int index); + static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom) { // Set by mov_read_tfhd(). mov_read_trun() will reject files missing tfhd. @@ -1814,6 +1816,15 @@ static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom) if ((ret = mov_read_mfra(c, pb)) < 0) { av_log(c->fc, AV_LOG_VERBOSE, "found a moof box but failed to " "read the mfra (may be a live ismv)\n"); + } else if (c->frag_index.nb_items > 0) { + // switch to the last fragment so that duration gets set during probe + // we don't get here during probing if sidx is present + int ret = mov_switch_root(c->fc, -1, c->frag_index.nb_items-1); + if (ret < 0) + return ret; + // switch back to this moof, seeking to the start of it + // this causes mov_read_default() to call us again + return mov_switch_root(c->fc, -1, 0); } } else { av_log(c->fc, AV_LOG_VERBOSE, "found a moof box but stream is not " -- 2.39.2
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".