diff options
author | Zhao Zhili <zhilizhao@tencent.com> | 2023-09-12 01:03:58 +0800 |
---|---|---|
committer | Zhao Zhili <zhilizhao@tencent.com> | 2023-09-14 18:49:51 +0800 |
commit | a8d9da4c8b574dab4f35f4b6802f52b1bc0156cc (patch) | |
tree | f7d76d0369bd5d384957bf47caddaa2b9cd75bc9 /libavformat | |
parent | 6434e440039910f12f7c08072b7db3c5e99c3025 (diff) | |
download | ffmpeg-a8d9da4c8b574dab4f35f4b6802f52b1bc0156cc.tar.gz |
avformat/mov: add interleaved_read option
For badly interleaved files, interleave packets from 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 <derek.buitenhuis@gmail.com>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/isom.h | 1 | ||||
-rw-r--r-- | libavformat/mov.c | 5 | ||||
-rw-r--r-- | libavformat/version.h | 2 |
3 files changed, 6 insertions, 2 deletions
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..93c1f9e929 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", "Interleave packets from multiple tracks at demuxer level", 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, \ |