Commit 306538fb57 for ffmpeg

commit 306538fb57eccdbd63c62cf4ce87a0d15873e697
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date:   Fri Nov 20 12:30:07 2026 -0600

    fftools/ffplay: leave room for the seek pre-roll in forward seeks

    A forward seek bounds the range below, so that it does not land before
    the current position. With AVSEEK_FLAG_PREROLL, the target moves back by
    the pre-roll but not below that bound, while the first packet still
    discards the full pre-roll: with a pre-roll longer than the room left,
    the discard reaches past the target, up to the end of the stream.

    Lower the bound by the largest audio pre-roll.

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 00e64d255e..0bb1d55cca 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -3115,6 +3115,27 @@ out:
     return ret;
 }

+/**
+ * The largest pre-roll of the audio streams, in AV_TIME_BASE units. A seek
+ * with AVSEEK_FLAG_PREROLL lands that much before its target, but no lower
+ * than min_ts, and discards it in full from the first packet.
+ */
+static int64_t seek_preroll(const AVFormatContext *ic)
+{
+    int64_t preroll = 0;
+
+    for (unsigned i = 0; i < ic->nb_streams; i++) {
+        const AVCodecParameters *par = ic->streams[i]->codecpar;
+
+        if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->seek_preroll > 0 &&
+            par->sample_rate > 0)
+            preroll = FFMAX(preroll, av_rescale_rnd(par->seek_preroll, AV_TIME_BASE,
+                                                    par->sample_rate, AV_ROUND_UP));
+    }
+
+    return preroll;
+}
+
 static int decode_interrupt_cb(void *ctx)
 {
     VideoState *is = ctx;
@@ -3487,6 +3508,9 @@ static int read_thread(void *arg)
             int64_t seek_max    = is->seek_rel < 0 ? seek_target - is->seek_rel - 2: INT64_MAX;
 // FIXME the +-2 is due to rounding being not done in the correct direction in generation
 //      of the seek_pos/seek_rel variables
+            if (seek_min != INT64_MIN && !(is->seek_flags & AVSEEK_FLAG_BYTE) &&
+                (is->ic->seek_flags & AVSEEK_FLAG_PREROLL))
+                seek_min -= seek_preroll(is->ic);

             ret = avformat_seek_file(is->ic, -1, seek_min, seek_target, seek_max, is->seek_flags);
             if (ret < 0) {