Commit 3d1cc82d17 for ffmpeg

commit 3d1cc82d17c2ffe032bc2265ca37d4c808c887f5
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date:   Sat Nov 7 16:56:41 2026 -0600

    avformat/seek: with AVSEEK_FLAG_PREROLL set, seek back by the pre-roll

    Moving the target back by the audio pre-roll lands a seek on the video
    stream one keyframe earlier, which a caller that copies the packets
    keeps, as with a concat inpoint (#25672).

    With the flag set, move the target back and discard the pre-roll, in
    av_seek_frame() as in avformat_seek_file(), and never pass the flag to
    the demuxer, so that a demuxer seeking through another one, as concat
    does, does not move the target back twice.

    When its own seek_flags has the flag, concat sets it on its inpoint
    seek, as a caller that decodes needs the pre-roll there too.

diff --git a/doc/APIchanges b/doc/APIchanges
index 4827b4ea29..1096fde9c9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2026-06-23.

 API changes, most recent first:

+2026-11-xx - xxxxxxxxxx - lavf 63.20.101 - avformat.h
+  With AVSEEK_FLAG_PREROLL set, avformat_seek_file() and av_seek_frame()
+  move the target back by the audio pre-roll, and discard the pre-roll
+  after the seek. Without it, a seek lands at the target.
+
 2026-11-xx - xxxxxxxxxx - lavf 63.20.100 - avformat.h
   Add AVSEEK_FLAG_PREROLL, for avformat_seek_file() to move the target back
   by the audio pre-roll.
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 80d4c5d220..6768627379 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2556,6 +2556,9 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  *                     is specified, in AV_TIME_BASE units.
  * @param flags        flags which select direction and seeking mode
  *
+ * With AVSEEK_FLAG_PREROLL set, timestamp moves back by the audio pre-roll,
+ * which is discarded after the seek, as with avformat_seek_file().
+ *
  * @return >= 0 on success
  */
 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
@@ -2577,21 +2580,24 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
  * keyframes (this may not be supported by all demuxers).
  * If flags contain AVSEEK_FLAG_BACKWARD, it is ignored.
  *
- * A seek by timestamp moves ts back by the largest
+ * If flags or AVFormatContext.seek_flags contain AVSEEK_FLAG_PREROLL, a seek
+ * by timestamp moves ts back by the largest
  * AVCodecParameters.seek_preroll of the audio streams that are not discarded,
  * whatever stream_index is, so that the decoders get their declared pre-roll
- * before ts. The target stays within min_ts and after the start of the
- * stream, so less room may be left. max_ts moves back as much, unless it is
- * INT64_MAX. If that seek fails, the seek is done to ts. This also applies to
- * av_seek_frame() with a demuxer that only implements this function.
+ * before ts. This is meant for a caller that decodes: the seek may land one
+ * keyframe earlier, which a caller that copies the packets would keep. The
+ * target stays within min_ts and after the start of the stream, so less room
+ * may be left. max_ts moves back as much, unless it is INT64_MAX. If that
+ * seek fails, the seek is done to ts.
  *
  * The first packet read after a seek from an audio stream carries
- * AV_PKT_DATA_SKIP_SAMPLES side data to discard the larger of the rest of the
- * priming (AVCodecParameters.initial_padding) and the seek pre-roll. The
- * discard supplies the stream's declared pre-roll; recovery beyond that
- * allowance depends on the codec and bitstream. Only the priming is discarded
- * on the first packet of the stream, and no pre-roll after the priming of a
- * stream whose start the seek targets.
+ * AV_PKT_DATA_SKIP_SAMPLES side data to discard the rest of the priming
+ * (AVCodecParameters.initial_padding) if the seek landed inside it. With
+ * AVSEEK_FLAG_PREROLL, it discards at least the seek pre-roll. The discard
+ * supplies the stream's declared pre-roll; recovery beyond that allowance
+ * depends on the codec and bitstream. Only the priming is discarded on the
+ * first packet of the stream, and no pre-roll after the priming of a stream
+ * whose start the seek targets.
  *
  * @param s            media file handle
  * @param stream_index index of the stream which is used as time base reference
diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index b2857b35d5..c979f5bccb 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -398,7 +398,8 @@ static int open_file(AVFormatContext *avf, unsigned fileno)
     if ((ret = match_streams(avf)) < 0)
         return ret;
     if (file->inpoint != AV_NOPTS_VALUE) {
-       if ((ret = avformat_seek_file(cat->avf, -1, INT64_MIN, file->inpoint, file->inpoint, 0)) < 0)
+       int flags = avf->seek_flags & AVSEEK_FLAG_PREROLL;
+       if ((ret = avformat_seek_file(cat->avf, -1, INT64_MIN, file->inpoint, file->inpoint, flags)) < 0)
            return ret;
     }
     return 0;
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 3f85744583..3c5157df4e 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1583,7 +1583,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
                 if (first) {
                     if (par->initial_padding > 0)
                         skip = par->initial_padding;
-                } else if (!(sti->seek_to_start && pkt->pts != AV_NOPTS_VALUE && !in_priming)) {
+                } else if (sti->seek_preroll &&
+                           !(sti->seek_to_start && pkt->pts != AV_NOPTS_VALUE && !in_priming)) {
                     // Past the first packet, the decoder also misses what
                     // came before.
                     skip = FFMAX(skip, par->seek_preroll);
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 4db9db85ce..a175828718 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -245,12 +245,18 @@ typedef struct FFStream {

     /**
      * Set by a seek, cleared on the next packet of the stream, which gets in
-     * skip_samples the rest of the priming if it is inside it, and unless it
-     * is the first packet of the stream, at least the seek pre-roll of the
-     * codec. After the priming, a seek to the start of the stream gets none.
+     * skip_samples the rest of the priming if it is inside it, and when
+     * seek_preroll is set and it is not the first packet of the stream, at
+     * least the seek pre-roll of the codec. After the priming, a seek to the
+     * start of the stream gets none.
      */
     int seek_discard;

+    /**
+     * Set with seek_discard when the seek had AVSEEK_FLAG_PREROLL.
+     */
+    int seek_preroll;
+
     /**
      * Set with seek_discard when the target of the seek is at or before the
      * start of this stream.
diff --git a/libavformat/seek.c b/libavformat/seek.c
index 06e1e6c452..0e9b3b15c4 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -638,32 +638,6 @@ static int seek_frame_internal(AVFormatContext *s, int stream_index,
         return -1;
 }

-int av_seek_frame(AVFormatContext *s, int stream_index,
-                  int64_t timestamp, int flags)
-{
-    int ret;
-
-    if (stream_index < -1 || stream_index >= (int)s->nb_streams)
-        return AVERROR(EINVAL);
-
-    if (ffifmt(s->iformat)->read_seek2 && !ffifmt(s->iformat)->read_seek) {
-        int64_t min_ts = INT64_MIN, max_ts = INT64_MAX;
-        if ((flags & AVSEEK_FLAG_BACKWARD))
-            max_ts = timestamp;
-        else
-            min_ts = timestamp;
-        return avformat_seek_file(s, stream_index, min_ts, timestamp, max_ts,
-                                  flags & ~AVSEEK_FLAG_BACKWARD);
-    }
-
-    ret = seek_frame_internal(s, stream_index, timestamp, flags);
-
-    if (ret >= 0)
-        ret = avformat_queue_attached_pictures(s);
-
-    return ret;
-}
-
 /**
  * The largest pre-roll of the audio streams that are not discarded, in the
  * units of the seek: the time base of the stream, or AV_TIME_BASE when no
@@ -712,6 +686,7 @@ static void request_seek_discard(AVFormatContext *s, int stream_index,
         FFStream *const sti = ffstream(st);

         sti->seek_discard  = 1;
+        sti->seek_preroll  = !!(flags & AVSEEK_FLAG_PREROLL);
         sti->seek_to_start = !(flags & (AVSEEK_FLAG_BYTE | AVSEEK_FLAG_FRAME)) &&
                              st->start_time != AV_NOPTS_VALUE &&
                              av_compare_ts(ts, time_base, st->start_time,
@@ -719,6 +694,63 @@ static void request_seek_discard(AVFormatContext *s, int stream_index,
     }
 }

+/**
+ * ts moved back by the pre-roll, without going below min_ts or before the
+ * start.
+ */
+static int64_t preroll_target(const AVFormatContext *s, int stream_index,
+                              int64_t min_ts, int64_t ts)
+{
+    int64_t start = stream_index >= 0 ? s->streams[stream_index]->start_time
+                                      : s->start_time;
+    int64_t target = FFMAX(av_sat_sub64(ts, seek_preroll(s, stream_index)),
+                           min_ts);
+
+    if (start != AV_NOPTS_VALUE)
+        target = FFMAX(target, FFMIN(start, ts));
+    return target;
+}
+
+int av_seek_frame(AVFormatContext *s, int stream_index,
+                  int64_t timestamp, int flags)
+{
+    int preroll_flag = flags & AVSEEK_FLAG_PREROLL;
+    int64_t target = timestamp;
+    int ret;
+
+    if (stream_index < -1 || stream_index >= (int)s->nb_streams)
+        return AVERROR(EINVAL);
+
+    if (ffifmt(s->iformat)->read_seek2 && !ffifmt(s->iformat)->read_seek) {
+        int64_t min_ts = INT64_MIN, max_ts = INT64_MAX;
+        if ((flags & AVSEEK_FLAG_BACKWARD))
+            max_ts = timestamp;
+        else
+            min_ts = timestamp;
+        return avformat_seek_file(s, stream_index, min_ts, timestamp, max_ts,
+                                  flags & ~AVSEEK_FLAG_BACKWARD);
+    }
+
+    flags &= ~AVSEEK_FLAG_PREROLL;
+    if (preroll_flag && !(flags & (AVSEEK_FLAG_BYTE | AVSEEK_FLAG_FRAME)))
+        target = preroll_target(s, stream_index, INT64_MIN, timestamp);
+
+    ret = seek_frame_internal(s, stream_index, target, flags);
+    // Without a known start, the earlier target may come before the first
+    // packet.
+    if (ret < 0 && target != timestamp) {
+        target = timestamp;
+        ret = seek_frame_internal(s, stream_index, timestamp, flags);
+    }
+    if (ret >= 0 && preroll_flag)
+        request_seek_discard(s, stream_index, target, flags | preroll_flag);
+
+    if (ret >= 0)
+        ret = avformat_queue_attached_pictures(s);
+
+    return ret;
+}
+
 static int seek_file(AVFormatContext *s, int stream_index, int64_t min_ts,
                      int64_t ts, int64_t max_ts, int flags)
 {
@@ -758,6 +790,7 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts,
                        int64_t ts, int64_t max_ts, int flags)
 {
     int64_t target = ts, target_max = max_ts;
+    int preroll_flag;
     int ret;

     if (min_ts > ts || max_ts < ts)
@@ -773,17 +806,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
 #endif
     flags |= s->seek_flags & (AVSEEK_FLAG_ANY | AVSEEK_FLAG_PREROLL);
     flags &= ~AVSEEK_FLAG_BACKWARD;
+    preroll_flag = flags & AVSEEK_FLAG_PREROLL;
+    // A demuxer that seeks through another one, as concat does, must not
+    // move the target back a second time.
+    flags &= ~AVSEEK_FLAG_PREROLL;

-    if (!(flags & (AVSEEK_FLAG_BYTE | AVSEEK_FLAG_FRAME))) {
-        int64_t preroll = seek_preroll(s, stream_index);
-        int64_t start = stream_index >= 0 ? s->streams[stream_index]->start_time
-                                          : s->start_time;
-
-        // Land early enough to decode the pre-roll, without leaving the
-        // range the caller asked for or going before the start.
-        target = FFMAX(av_sat_sub64(ts, preroll), min_ts);
-        if (start != AV_NOPTS_VALUE)
-            target = FFMAX(target, FFMIN(start, ts));
+    if (preroll_flag && !(flags & (AVSEEK_FLAG_BYTE | AVSEEK_FLAG_FRAME))) {
+        target = preroll_target(s, stream_index, min_ts, ts);
         // Move the finite upper bound back by the same amount as the target.
         // An open upper bound stays open.
         if (max_ts != INT64_MAX)
@@ -798,7 +827,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         ret = seek_file(s, stream_index, min_ts, ts, max_ts, flags);
     }
     if (ret >= 0)
-        request_seek_discard(s, stream_index, target, flags);
+        request_seek_discard(s, stream_index, target, flags | preroll_flag);
     return ret;
 }

diff --git a/libavformat/version.h b/libavformat/version.h
index de9cc8e31d..f4a26c2870 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"

 #define LIBAVFORMAT_VERSION_MINOR  20
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101

 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
diff --git a/tests/ref/fate/preroll-aac-concat-inpoint b/tests/ref/fate/preroll-aac-concat-inpoint
index e9f9d75572..7aeb9236d3 100644
--- a/tests/ref/fate/preroll-aac-concat-inpoint
+++ b/tests/ref/fate/preroll-aac-concat-inpoint
@@ -1,4 +1,4 @@
-packet|stream_index=0|pts=-1000|flags=K__
-packet|stream_index=1|pts=-986|flags=K__|side_datum/skip_samples:skip_samples=1024
-packet|stream_index=1|pts=-965|flags=K__
-packet|stream_index=1|pts=-944|flags=K__
+packet|stream_index=0|pts=0|flags=K__
+packet|stream_index=1|pts=38|flags=K__
+packet|stream_index=1|pts=59|flags=K__
+packet|stream_index=1|pts=80|flags=K__
diff --git a/tests/ref/fate/preroll-aac-concat-seek b/tests/ref/fate/preroll-aac-concat-seek
index 895a3c46ea..0bdc1329cb 100644
--- a/tests/ref/fate/preroll-aac-concat-seek
+++ b/tests/ref/fate/preroll-aac-concat-seek
@@ -1,6 +1,6 @@
-ret: 0         st: 0 flags:1 dts: 0.462948 pts: 0.462948 pos:   2363 size:    26 skip:1024 discard:0
-ret: 0         st: 0 flags:1 dts: 0.486168 pts: 0.486168 pos:   2389 size:    27
+ret: 0         st: 0 flags:1 dts: 0.486168 pts: 0.486168 pos:   2389 size:    27 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 0.509388 pts: 0.509388 pos:   2416 size:    27
+ret: 0         st: 0 flags:1 dts: 0.532608 pts: 0.532608 pos:   2443 size:    28
 ret: 0         st:-1 flags:0  ts:-1.000000
 ret: 0         st: 0 flags:1 dts:-0.047891 pts:-0.047891 pos:   1366 size:     6 skip:2112 discard:0
 ret: 0         st: 0 flags:1 dts:-0.024671 pts:-0.024671 pos:   1372 size:   251
@@ -14,17 +14,17 @@ ret: 0         st: 0 flags:1 dts: 0.811247 pts: 0.811247 pos:   2774 size:    27
 ret: 0         st: 0 flags:1 dts: 0.834467 pts: 0.834467 pos:   2801 size:    28
 ret: 0         st: 0 flags:1 dts: 0.857687 pts: 0.857687 pos:   2829 size:    28
 ret: 0         st: 0 flags:1  ts: 1.682494
-ret: 0         st: 0 flags:1 dts: 1.623946 pts: 1.623946 pos:   3903 size:    39 skip:1024 discard:0
-ret: 0         st: 0 flags:1 dts: 1.647166 pts: 1.647166 pos:   3942 size:    42
+ret: 0         st: 0 flags:1 dts: 1.647166 pts: 1.647166 pos:   3942 size:    42 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 1.670385 pts: 1.670385 pos:   3984 size:    41
+ret: 0         st: 0 flags:1 dts: 1.693605 pts: 1.693605 pos:   4025 size:    41
 ret: 0         st:-1 flags:0  ts:-0.423332
 ret: 0         st: 0 flags:1 dts:-0.047891 pts:-0.047891 pos:   1366 size:     6 skip:2112 discard:0
 ret: 0         st: 0 flags:1 dts:-0.024671 pts:-0.024671 pos:   1372 size:   251
 ret: 0         st: 0 flags:1 dts:-0.001451 pts:-0.001451 pos:   1623 size:   168
 ret: 0         st:-1 flags:1  ts: 0.470835
-ret: 0         st: 0 flags:1 dts: 0.416508 pts: 0.416508 pos:   2309 size:    27 skip:1024 discard:0
-ret: 0         st: 0 flags:1 dts: 0.439728 pts: 0.439728 pos:   2336 size:    27
+ret: 0         st: 0 flags:1 dts: 0.439728 pts: 0.439728 pos:   2336 size:    27 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 0.462948 pts: 0.462948 pos:   2363 size:    26
+ret: 0         st: 0 flags:1 dts: 0.486168 pts: 0.486168 pos:   2389 size:    27
 ret: 0         st: 0 flags:0  ts: 1.365011
 ret: 0         st: 0 flags:1 dts: 1.368526 pts: 1.368526 pos:   3465 size:    30 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 1.391746 pts: 1.391746 pos:   3495 size:    39
@@ -38,9 +38,9 @@ ret: 0         st: 0 flags:1 dts: 0.161088 pts: 0.161088 pos:   2014 size:    27
 ret: 0         st: 0 flags:1 dts: 0.184308 pts: 0.184308 pos:   2041 size:    27
 ret: 0         st: 0 flags:1 dts: 0.207528 pts: 0.207528 pos:   2068 size:    27
 ret: 0         st:-1 flags:1  ts: 1.047503
-ret: 0         st: 0 flags:1 dts: 0.997007 pts: 0.997007 pos:   2996 size:    28 skip:1024 discard:0
-ret: 0         st: 0 flags:1 dts: 1.020227 pts: 1.020227 pos:   3024 size:    28
+ret: 0         st: 0 flags:1 dts: 1.020227 pts: 1.020227 pos:   3024 size:    28 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 1.043447 pts: 1.043447 pos:   3052 size:    27
+ret: 0         st: 0 flags:1 dts: 1.066667 pts: 1.066667 pos:   3079 size:    28
 ret: 0         st: 0 flags:0  ts: 1.941678
 ret: 0         st: 0 flags:1 dts: 1.949025 pts: 1.949025 pos:   4474 size:    41 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 1.972245 pts: 1.972245 pos:   4515 size:    39
@@ -54,17 +54,17 @@ ret: 0         st: 0 flags:1 dts: 0.741587 pts: 0.741587 pos:   2691 size:    28
 ret: 0         st: 0 flags:1 dts: 0.764807 pts: 0.764807 pos:   2719 size:    28
 ret: 0         st: 0 flags:1 dts: 0.788027 pts: 0.788027 pos:   2747 size:    27
 ret: 0         st:-1 flags:1  ts: 1.624171
-ret: 0         st: 0 flags:1 dts: 1.577506 pts: 1.577506 pos:   3821 size:    41 skip:1024 discard:0
-ret: 0         st: 0 flags:1 dts: 1.600726 pts: 1.600726 pos:   3862 size:    41
+ret: 0         st: 0 flags:1 dts: 1.600726 pts: 1.600726 pos:   3862 size:    41 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 1.623946 pts: 1.623946 pos:   3903 size:    39
+ret: 0         st: 0 flags:1 dts: 1.647166 pts: 1.647166 pos:   3942 size:    42
 ret: 0         st: 0 flags:0  ts:-0.481655
 ret: 0         st: 0 flags:1 dts:-0.047891 pts:-0.047891 pos:   1366 size:     6 skip:2112 discard:0
 ret: 0         st: 0 flags:1 dts:-0.024671 pts:-0.024671 pos:   1372 size:   251
 ret: 0         st: 0 flags:1 dts:-0.001451 pts:-0.001451 pos:   1623 size:   168
 ret: 0         st: 0 flags:1  ts: 0.412494
-ret: 0         st: 0 flags:1 dts: 0.346848 pts: 0.346848 pos:   2229 size:    26 skip:1024 discard:0
-ret: 0         st: 0 flags:1 dts: 0.370068 pts: 0.370068 pos:   2255 size:    27
+ret: 0         st: 0 flags:1 dts: 0.370068 pts: 0.370068 pos:   2255 size:    27 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 0.393288 pts: 0.393288 pos:   2282 size:    27
+ret: 0         st: 0 flags:1 dts: 0.416508 pts: 0.416508 pos:   2309 size:    27
 ret: 0         st:-1 flags:0  ts: 1.306672
 ret: 0         st: 0 flags:1 dts: 1.322086 pts: 1.322086 pos:   3405 size:    30 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 1.345306 pts: 1.345306 pos:   3435 size:    30
@@ -78,9 +78,9 @@ ret: 0         st: 0 flags:1 dts: 0.114649 pts: 0.114649 pos:   1961 size:    26
 ret: 0         st: 0 flags:1 dts: 0.137868 pts: 0.137868 pos:   1987 size:    27
 ret: 0         st: 0 flags:1 dts: 0.161088 pts: 0.161088 pos:   2014 size:    27
 ret: 0         st: 0 flags:1  ts: 0.989184
-ret: 0         st: 0 flags:1 dts: 0.927347 pts: 0.927347 pos:   2913 size:    27 skip:1024 discard:0
-ret: 0         st: 0 flags:1 dts: 0.950567 pts: 0.950567 pos:   2940 size:    28
+ret: 0         st: 0 flags:1 dts: 0.950567 pts: 0.950567 pos:   2940 size:    28 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 0.973787 pts: 0.973787 pos:   2968 size:    28
+ret: 0         st: 0 flags:1 dts: 0.997007 pts: 0.997007 pos:   2996 size:    28
 ret: 0         st:-1 flags:0  ts: 1.883340
 ret: 0         st: 0 flags:1 dts: 1.902585 pts: 1.902585 pos:   4392 size:    41 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 1.925805 pts: 1.925805 pos:   4433 size:    41
@@ -94,14 +94,14 @@ ret: 0         st: 0 flags:1 dts: 0.671927 pts: 0.671927 pos:   2609 size:    27
 ret: 0         st: 0 flags:1 dts: 0.695147 pts: 0.695147 pos:   2636 size:    27
 ret: 0         st: 0 flags:1 dts: 0.718367 pts: 0.718367 pos:   2663 size:    28
 ret: 0         st: 0 flags:1  ts: 1.565850
-ret: 0         st: 0 flags:1 dts: 1.507846 pts: 1.507846 pos:   3699 size:    39 skip:1024 discard:0
-ret: 0         st: 0 flags:1 dts: 1.531066 pts: 1.531066 pos:   3738 size:    42
+ret: 0         st: 0 flags:1 dts: 1.531066 pts: 1.531066 pos:   3738 size:    42 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 1.554286 pts: 1.554286 pos:   3780 size:    41
+ret: 0         st: 0 flags:1 dts: 1.577506 pts: 1.577506 pos:   3821 size:    41
 ret: 0         st:-1 flags:0  ts:-0.539992
 ret: 0         st: 0 flags:1 dts:-0.047891 pts:-0.047891 pos:   1366 size:     6 skip:2112 discard:0
 ret: 0         st: 0 flags:1 dts:-0.024671 pts:-0.024671 pos:   1372 size:   251
 ret: 0         st: 0 flags:1 dts:-0.001451 pts:-0.001451 pos:   1623 size:   168
 ret: 0         st:-1 flags:1  ts: 0.354175
-ret: 0         st: 0 flags:1 dts: 0.300408 pts: 0.300408 pos:   2175 size:    27 skip:1024 discard:0
-ret: 0         st: 0 flags:1 dts: 0.323628 pts: 0.323628 pos:   2202 size:    27
+ret: 0         st: 0 flags:1 dts: 0.323628 pts: 0.323628 pos:   2202 size:    27 skip:1024 discard:0
 ret: 0         st: 0 flags:1 dts: 0.346848 pts: 0.346848 pos:   2229 size:    26
+ret: 0         st: 0 flags:1 dts: 0.370068 pts: 0.370068 pos:   2255 size:    27
diff --git a/tests/ref/seek/mkv-codec-delay b/tests/ref/seek/mkv-codec-delay
index f228155290..779298347f 100644
--- a/tests/ref/seek/mkv-codec-delay
+++ b/tests/ref/seek/mkv-codec-delay
@@ -2,47 +2,47 @@ ret: 0         st: 0 flags:1 dts:-0.007000 pts:-0.007000 pos:    748 size:   320
 ret: 0         st:-1 flags:0  ts:-1.000000
 ret: 0         st: 0 flags:1 dts:-0.007000 pts:-0.007000 pos:    748 size:   320 skip:312 discard:0
 ret: 0         st:-1 flags:1  ts: 1.894167
-ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:3840 discard:706
+ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:0 discard:706
 ret: 0         st: 0 flags:0  ts: 0.788000
-ret: 0         st: 0 flags:1 dts: 0.794000 pts: 0.794000 pos:   7358 size:   154 skip:3840 discard:0
+ret: 0         st: 0 flags:1 dts: 0.794000 pts: 0.794000 pos:   7358 size:   154
 ret: 0         st: 0 flags:1  ts:-0.317000
 ret: 0         st: 0 flags:1 dts:-0.007000 pts:-0.007000 pos:    748 size:   320 skip:312 discard:0
 ret:-1         st:-1 flags:0  ts: 2.576668
 ret: 0         st:-1 flags:1  ts: 1.470835
-ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:3840 discard:706
+ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:0 discard:706
 ret: 0         st: 0 flags:0  ts: 0.365000
-ret: 0         st: 0 flags:1 dts: 0.374000 pts: 0.374000 pos:   3963 size:   150 skip:3840 discard:0
+ret: 0         st: 0 flags:1 dts: 0.374000 pts: 0.374000 pos:   3963 size:   150
 ret: 0         st: 0 flags:1  ts:-0.741000
 ret: 0         st: 0 flags:1 dts:-0.007000 pts:-0.007000 pos:    748 size:   320 skip:312 discard:0
 ret:-1         st:-1 flags:0  ts: 2.153336
 ret: 0         st:-1 flags:1  ts: 1.047503
-ret: 0         st: 0 flags:1 dts: 0.954000 pts: 0.954000 pos:   8643 size:   154 skip:3840 discard:0
+ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:0 discard:706
 ret: 0         st: 0 flags:0  ts:-0.058000
 ret: 0         st: 0 flags:1 dts:-0.007000 pts:-0.007000 pos:    748 size:   320 skip:312 discard:0
 ret: 0         st: 0 flags:1  ts: 2.836000
-ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:3840 discard:706
+ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:0 discard:706
 ret:-1         st:-1 flags:0  ts: 1.730004
 ret: 0         st:-1 flags:1  ts: 0.624171
-ret: 0         st: 0 flags:1 dts: 0.534000 pts: 0.534000 pos:   5251 size:   150 skip:3840 discard:0
+ret: 0         st: 0 flags:1 dts: 0.614000 pts: 0.614000 pos:   5903 size:   159
 ret: 0         st: 0 flags:0  ts:-0.482000
 ret: 0         st: 0 flags:1 dts:-0.007000 pts:-0.007000 pos:    748 size:   320 skip:312 discard:0
 ret: 0         st: 0 flags:1  ts: 2.413000
-ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:3840 discard:706
+ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:0 discard:706
 ret:-1         st:-1 flags:0  ts: 1.306672
 ret: 0         st:-1 flags:1  ts: 0.200839
-ret: 0         st: 0 flags:1 dts: 0.114000 pts: 0.114000 pos:   1855 size:   158 skip:3840 discard:0
+ret: 0         st: 0 flags:1 dts: 0.194000 pts: 0.194000 pos:   2512 size:   159
 ret: 0         st: 0 flags:0  ts:-0.905000
 ret: 0         st: 0 flags:1 dts:-0.007000 pts:-0.007000 pos:    748 size:   320 skip:312 discard:0
 ret: 0         st: 0 flags:1  ts: 1.989000
-ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:3840 discard:706
+ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:0 discard:706
 ret: 0         st:-1 flags:0  ts: 0.883340
-ret: 0         st: 0 flags:1 dts: 0.894000 pts: 0.894000 pos:   8154 size:   155 skip:3840 discard:0
+ret: 0         st: 0 flags:1 dts: 0.894000 pts: 0.894000 pos:   8154 size:   155
 ret: 0         st:-1 flags:1  ts:-0.222493
 ret: 0         st: 0 flags:1 dts:-0.007000 pts:-0.007000 pos:    748 size:   320 skip:312 discard:0
 ret:-1         st: 0 flags:0  ts: 2.672000
 ret: 0         st: 0 flags:1  ts: 1.566000
-ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:3840 discard:706
+ret: 0         st: 0 flags:1 dts: 1.014000 pts: 1.014000 pos:   9306 size:   268 skip:0 discard:706
 ret: 0         st:-1 flags:0  ts: 0.460008
-ret: 0         st: 0 flags:1 dts: 0.474000 pts: 0.474000 pos:   4768 size:   153 skip:3840 discard:0
+ret: 0         st: 0 flags:1 dts: 0.474000 pts: 0.474000 pos:   4768 size:   153
 ret: 0         st:-1 flags:1  ts:-0.645825
 ret: 0         st: 0 flags:1 dts:-0.007000 pts:-0.007000 pos:    748 size:   320 skip:312 discard:0