This one is perhaps a bit dubious, but on frags.mp4 it saves a seek. I have no strong feelings on this patch, it just struck me as far simpler to always read mfra
I checked the ISO/IEC spec and mfra may be present in any file that is isom branded. Usually it is only present for fragmented files I also noticed movenc writes moof after mdat rather than before it. This forces movdec to read more than would otherwise be necessary /Tomas
From db3d3e7bf6d12493e571506dc85003d5f957e964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <g...@haerdin.se> Date: Wed, 11 Dec 2024 14:59:10 +0100 Subject: [PATCH 2/3] lavf/mov: Always try to parse mfra Parsing mfra even before encountering moof saves a seek on some files --- libavformat/isom.h | 1 - libavformat/mov.c | 27 ++++++++++----------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index f18b15bbff..e73db77ebe 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -338,7 +338,6 @@ typedef struct MOVContext { int bitrates_count; int moov_retry; int use_mfra_for; - int has_looked_for_mfra; int use_tfdt; MOVFragmentIndex frag_index; int atom_depth; diff --git a/libavformat/mov.c b/libavformat/mov.c index cfcd64b7db..4f90d03f62 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -85,7 +85,6 @@ typedef struct MOVParseTableEntry { } MOVParseTableEntry; static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom); -static int mov_read_mfra(MOVContext *c, AVIOContext *f); static void mov_free_stream_context(AVFormatContext *s, AVStream *st); static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size, int count, int duration); @@ -1804,22 +1803,6 @@ static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom) { // Set by mov_read_tfhd(). mov_read_trun() will reject files missing tfhd. c->fragment.found_tfhd = 0; - - if (!c->has_looked_for_mfra) { - c->has_looked_for_mfra = 1; - if (pb->seekable & AVIO_SEEKABLE_NORMAL) { - int ret; - av_log(c->fc, AV_LOG_VERBOSE, "stream has moof boxes, will look " - "for a mfra\n"); - 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 { - av_log(c->fc, AV_LOG_VERBOSE, "found a moof box but stream is not " - "seekable, can not look for mfra\n"); - } - } c->fragment.moof_offset = c->fragment.implicit_offset = avio_tell(pb) - 8; av_log(c->fc, AV_LOG_TRACE, "moof offset %"PRIx64"\n", c->fragment.moof_offset); c->frag_index.current = update_frag_index(c, c->fragment.moof_offset); @@ -10509,6 +10492,16 @@ static int mov_read_header(AVFormatContext *s) else atom.size = INT64_MAX; + if (pb->seekable & AVIO_SEEKABLE_NORMAL) { + int ret; + av_log(mov->fc, AV_LOG_VERBOSE, "looking for mfra\n"); + if ((ret = mov_read_mfra(mov, pb)) < 0) { + av_log(mov->fc, AV_LOG_VERBOSE, "no mfra found\n"); + } + } else { + av_log(mov->fc, AV_LOG_VERBOSE, "file not seekable, will not look for mfra\n"); + } + /* check MOV header */ do { if (mov->moov_retry) -- 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".