From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 840F34754C for ; Mon, 11 Sep 2023 17:10:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6A24868C96A; Mon, 11 Sep 2023 20:10:51 +0300 (EEST) Received: from out203-205-221-153.mail.qq.com (out203-205-221-153.mail.qq.com [203.205.221.153]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AABD668C801 for ; Mon, 11 Sep 2023 20:10:43 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1694452241; bh=f7tL8WUVpj1UDmST7mm0WB/ZK3b4x9SM2p/Q1m2H+mc=; h=From:To:Cc:Subject:Date; b=zDs0W608TejJ+k30SvQ7tIkBge8oEzAEH0b0pg6Ts5FWOBALHcJBIe/Uz7NXZ029j IgSEqU+4gxJl+Yw9+EZCt7596K6Ubu/6cUxMQQn4vDhS6qXAIiHhAY7C2x9GBYFo5l 988YaidBbYW6DPJUSQVxo+fbbrlWxGUQAiKpNdVc= Received: from localhost.localdomain ([121.35.187.136]) by newxmesmtplogicsvrsza12-0.qq.com (NewEsmtp) with SMTP id 11D3AE7C; Tue, 12 Sep 2023 01:04:29 +0800 X-QQ-mid: xmsmtpt1694451869thm4d1je5 Message-ID: X-QQ-XMAILINFO: MMq8nqC7jH0BjMLmiy4wcr3PGM8pgZol1mvjMwmVQ0N0bNsiRY0vFo0jCCDm7f /+mN3h4fEXpE/4/QarkiN07WUOK63YqVyzGlxDejB+ITP81fwmYRLGMQ4z6snwqLSOZhx3DqxrMd wsAHguSF9gmNePR2trj7mcIb9UR6qYTxdXoTDUx7/H8nDQAErgLoX/1tXrUw1jaAhNOHT32nRiiu OP/+W6XNCj/LCY6LkuNVKQgBj9Yr0Q7xRQS3HDnXcaQu1DdQZh7b84e8BaAljSXK+10HK5RcHjUt n9f7rbempE1nysmLwYuiCxyxbLsM/09M/sNgUmvCdhaKZMRZOEHqD/CIXR/B4MlpwCoM7dqTTGYP 6yJ/WgD2swO0vmNARU3qlIkh77q4GIn1Zvl3jxPWJQ8kvW4dyXk5MNTB+T7S7K2fkrHWZcBxfqiJ lrtb/v0lYIAjpI5wf45aDpjxGlE3bMav756DOQrffAb+EtiIspz9R25UcFkwNAvzykdW1b/DeN9C 5apWCmFCgf1X3S7nInStVpaDhHmff7qCCBmWYCA4Wjki95IyWokoeiStu8Xkt0GrnwrRyxFQWMUx fgZ2Z3PIA1j/2tQY1WCuWHFMfz1NamxI7mmccZCuROhSjn0LVcnybhfEQ3DwyIB4RI4L5lm3Q4Rn sMsttJsG7jGycciErkmCUbftmdCZpIy7zZXZXHdMiOkBENVzbwqk25dNb04ub1js9q7RCloh58aW 4QmCuCEMyp3b07u6Vf5F2alEIx08XbB+YNdEJ5T+CXF90cbtXCFWQnp9fSYJJJ/mCG9rJiROkVj/ ND0mkg0iNKrsPoB6Hx1m+oCNBXoFzljNTsKmv2Xi2w/qz9wzubiqgodCQ5jNkqVwE6/wvFCG9epn pi1SqMh2vuDKRprOfB3QGiioQt+UnpVbP0k0N3q1Ju0NQGLuw0qHfGe253JNY9RFuWDeTtO1FMgE 74mwrV2Wu9FaoIaLjFg2rhZ86Cb0A/8MahN/0gn2Dty097aE9lhkpVU3a8OLDm3kYWFmtZrkw= X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Sep 2023 01:03:58 +0800 X-OQ-MSGID: <20230911170358.1842-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] avformat/mov: add interleaved_read option X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zhao Zhili , Derek Buitenhuis Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Zhao Zhili For bad interleaved files, manually interleave multiple tracks at the demuxer level can trigger seeking back and forth, which can be dramatically slow depending on the protocol. Demuxer level interleave can be useless sometimes, e.g., reading mp4 via http and then transcoding/remux to DASH. Disable this option when you don't need the demuxer level interleave, and want to avoid the IO penalizes. Co-authored-by: Derek Buitenhuis Signed-off-by: Zhao Zhili --- v3: update doc v2: rename option This issue is well known. Two samples can be found at here http://ffmpeg.org/pipermail/ffmpeg-devel/2022-December/304951.html doc/demuxers.texi | 7 +++++++ libavformat/isom.h | 1 + libavformat/mov.c | 5 ++++- libavformat/version.h | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/demuxers.texi b/doc/demuxers.texi index 2d33b47a56..ca1563abb0 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -779,6 +779,13 @@ cast to int32 are used to adjust onward dts. Unit is the track time scale. Range is 0 to UINT_MAX. Default is @code{UINT_MAX - 48000*10} which allows upto a 10 second dts correction for 48 kHz audio streams while accommodating 99.9% of @code{uint32} range. + +@item interleaved_read +Interleave packets from multiple tracks at demuxer level. For badly interleaved files, this prevents playback issues +caused by large gaps between packets in different tracks, as MOV/MP4 do not have packet placement requirements. +However, this can cause excessive seeking on very badly interleaved files, due to seeking between tracks, so disabling +it may prevent I/O issues, at the expense of playback. + @end table @subsection Audible AAX diff --git a/libavformat/isom.h b/libavformat/isom.h index 4b1cd42f0f..3d375d7a46 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -327,6 +327,7 @@ typedef struct MOVContext { int64_t extent_offset; } *avif_info; int avif_info_size; + int interleaved_read; } MOVContext; int ff_mp4_read_descr_len(AVIOContext *pb); diff --git a/libavformat/mov.c b/libavformat/mov.c index aa1d9e4ccc..8ad5f0b646 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -8780,6 +8780,8 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) AVIndexEntry *sample = NULL; int64_t best_dts = INT64_MAX; int i; + MOVContext *mov = s->priv_data; + int no_interleave = !mov->interleaved_read || !(s->pb->seekable & AVIO_SEEKABLE_NORMAL); for (i = 0; i < s->nb_streams; i++) { AVStream *avst = s->streams[i]; FFStream *const avsti = ffstream(avst); @@ -8788,7 +8790,7 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) AVIndexEntry *current_sample = &avsti->index_entries[msc->current_sample]; int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale); av_log(s, AV_LOG_TRACE, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); - if (!sample || (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && current_sample->pos < sample->pos) || + if (!sample || (no_interleave && current_sample->pos < sample->pos) || ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && dts != AV_NOPTS_VALUE && ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || @@ -9282,6 +9284,7 @@ static const AVOption mov_options[] = { { "enable_drefs", "Enable external track support.", OFFSET(enable_drefs), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, { "max_stts_delta", "treat offsets above this value as invalid", OFFSET(max_stts_delta), AV_OPT_TYPE_INT, {.i64 = UINT_MAX-48000*10 }, 0, UINT_MAX, .flags = AV_OPT_FLAG_DECODING_PARAM }, + { "interleaved_read", "Manually interleave between multiple tracks", OFFSET(interleaved_read), AV_OPT_TYPE_BOOL, {.i64 = 1 }, 0, 1, .flags = AV_OPT_FLAG_DECODING_PARAM }, { NULL }, }; diff --git a/libavformat/version.h b/libavformat/version.h index cb67e0a1f8..e41362ac9d 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ #include "version_major.h" #define LIBAVFORMAT_VERSION_MINOR 12 -#define LIBAVFORMAT_VERSION_MICRO 100 +#define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".