@@ -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);
@@ -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 },
};
@@ -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, \