[FFmpeg-devel] lavf/movdec: add position_order option

Submitted by Rodger Combs on Sept. 21, 2019, 5:58 p.m.

Details

Message ID 20190921175820.55905-1-rodger.combs@gmail.com
State New
Headers show

Commit Message

Rodger Combs Sept. 21, 2019, 5:58 p.m.
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(-)

Comments

Carl Eugen Hoyos Sept. 21, 2019, 7:46 p.m.
Am Sa., 21. Sept. 2019 um 19:58 Uhr schrieb Rodger Combs
<rodger.combs@gmail.com>:

> +    { "position_order", "Read packets in position order (rather than timestamp order)",
> +        OFFSET(position_order), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },

Should this also say "avoids seeks"?

Carl Eugen
Andreas Rheinhardt Sept. 22, 2019, 8:19 a.m.
Rodger Combs:
> 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.
> ---

Did you test whether this fixes tickets #7592 and #7891?

- Andreas
Rodger Combs Sept. 22, 2019, 8:30 a.m.
> On Sep 22, 2019, at 03:19, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> 
> Rodger Combs:
>> 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.
>> ---
> 
> Did you test whether this fixes tickets #7592 and #7891?
> 
> - Andreas

Tested just now; I can't validate 7592 as the sample link is dead, but playback of the files in 7891 over network (in either mpv or ffplay) improves dramatically with this option set.

> 
> _______________________________________________
> 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".

Patch hide | download patch | download mbox

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, \