This allows reading packets linearly, which prevents large numbers of unnecessary seeks in poorly-interleaved files with consumer software that handles those cases well on its own. --- libavformat/isom.h | 1 + libavformat/mov.c | 11 +++++++---- libavformat/version.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/libavformat/isom.h b/libavformat/isom.h index 69452cae8e..3e29e9877d 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -288,6 +288,7 @@ typedef struct MOVContext { int decryption_key_len; int enable_drefs; int32_t movie_display_matrix[3][3]; ///< display matrix from mvhd + int position_order; } MOVContext; int ff_mp4_read_descr_len(AVIOContext *pb); diff --git a/libavformat/mov.c b/libavformat/mov.c index 675b915906..a1559b8a8f 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7626,8 +7626,10 @@ static int mov_read_header(AVFormatContext *s) static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) { + MOVContext *mov = s->priv_data; AVIndexEntry *sample = NULL; int64_t best_dts = INT64_MAX; + int use_pos = mov->position_order || !(s->pb->seekable & AVIO_SEEKABLE_NORMAL); int i; for (i = 0; i < s->nb_streams; i++) { AVStream *avst = s->streams[i]; @@ -7636,11 +7638,10 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) AVIndexEntry *current_sample = &avst->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) || - ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && - ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && + if (!sample || (use_pos ? (current_sample->pos < sample->pos) : + (((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || - (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) { + (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts))))))) { sample = current_sample; best_dts = dts; *st = avst; @@ -8017,6 +8018,8 @@ static const AVOption mov_options[] = { { "decryption_key", "The media decryption key (hex)", OFFSET(decryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, { "enable_drefs", "Enable external track support.", OFFSET(enable_drefs), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, + { "position_order", "Read packets in position order (rather than timestamp order)", + OFFSET(position_order), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, { NULL }, }; diff --git a/libavformat/version.h b/libavformat/version.h index edfa73fb97..2eb14659d0 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -33,7 +33,7 @@ // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 #define LIBAVFORMAT_VERSION_MINOR 32 -#define LIBAVFORMAT_VERSION_MICRO 104 +#define LIBAVFORMAT_VERSION_MICRO 105 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- 2.21.0 _______________________________________________ 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".