History

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.

Zhao Zhili committed 3 years ago

Commit a8d9da41 parent 6434e444 files · +13 −2Browse files

Showing the changes to libavformat (3 of 4 files). Show all

Unified · Split

3 files
  1. libavformat/isom.h +1 −0
  2. libavformat/mov.c +4 −1
  3. libavformat/version.h +1 −1
libavformat/isom.h+1−0
@@ -327,6 +327,7 @@ typedef struct MOVContext { · 326 unmodified lines
327327 int64_t extent_offset;
328328 } *avif_info;
329329 int avif_info_size;
330+ int interleaved_read;
330331 } MOVContext;
331332
332333 int ff_mp4_read_descr_len(AVIOContext *pb);
libavformat/mov.c+4−1
@@ -8780,6 +8780,8 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) · 8779 unmodified lines
87808780 AVIndexEntry *sample = NULL;
87818781 int64_t best_dts = INT64_MAX;
87828782 int i;
8783+ MOVContext *mov = s->priv_data;
8784+ int no_interleave = !mov->interleaved_read || !(s->pb->seekable & AVIO_SEEKABLE_NORMAL);
87838785 for (i = 0; i < s->nb_streams; i++) {
87848786 AVStream *avst = s->streams[i];
87858787 FFStream *const avsti = ffstream(avst);
@@ -8788,7 +8790,7 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) · 2 unmodified lines
87888790 AVIndexEntry *current_sample = &avsti->index_entries[msc->current_sample];
87898791 int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale);
87908792 av_log(s, AV_LOG_TRACE, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
8791− if (!sample || (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && current_sample->pos < sample->pos) ||
8793+ if (!sample || (no_interleave && current_sample->pos < sample->pos) ||
87928794 ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
87938795 ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && dts != AV_NOPTS_VALUE &&
87948796 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) ||
@@ -9282,6 +9284,7 @@ static const AVOption mov_options[] = { · 487 unmodified lines
92829284 { "enable_drefs", "Enable external track support.", OFFSET(enable_drefs), AV_OPT_TYPE_BOOL,
92839285 {.i64 = 0}, 0, 1, FLAGS },
92849286 { "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 },
9287+ { "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 },
92859288
92869289 { NULL },
92879290 };
libavformat/version.h+1−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232 #include "version_major.h"
3333
3434 #define LIBAVFORMAT_VERSION_MINOR 12
35−#define LIBAVFORMAT_VERSION_MICRO 100
35+#define LIBAVFORMAT_VERSION_MICRO 101
3636
3737 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
3838 LIBAVFORMAT_VERSION_MINOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t