Commit 8b3525e718 for ffmpeg

commit 8b3525e7182535382aae97f4ed8ae47a547ddd81
Author: Julius Bairaktaris <julius@bairaktaris.de>
Date:   Mon Sep 28 07:29:03 2026 +0200

    avcodec/vp9: take the discard flag from the packet that shows a frame

    A show_existing_frame packet outputs a reference to an earlier frame,
    whose AV_FRAME_FLAG_DISCARD comes from the packet that coded it. If that
    packet was discarded, the shown frame is dropped too. Take the flag from
    the showing packet, as is already done for pts and pkt_dts.
    fate-vp9-trim-preroll covers this with the trim bsf's preroll option.

    Assisted-by: Claude Opus 5.5
    Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index ce4e197c9d..c20b1002c1 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -1649,6 +1649,10 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
             return ret;
         frame->pts     = pkt->pts;
         frame->pkt_dts = pkt->dts;
+        if (pkt->flags & AV_PKT_FLAG_DISCARD)
+            frame->flags |= AV_FRAME_FLAG_DISCARD;
+        else
+            frame->flags &= ~AV_FRAME_FLAG_DISCARD;
         *got_frame = 1;
         return pkt->size;
     }
diff --git a/tests/fate/vpx.mak b/tests/fate/vpx.mak
index 9c52fc4898..764db4ce8b 100644
--- a/tests/fate/vpx.mak
+++ b/tests/fate/vpx.mak
@@ -141,6 +141,9 @@ FATE_VP9-$(call FRAMEMD5, IVF, VP9, SCALE_FILTER) += fate-vp9-05-resize
 fate-vp9-05-resize: CMD = framemd5 -i $(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-05-resize.ivf -s 352x288 -sws_flags bitexact+bilinear
 fate-vp9-05-resize: REF = $(SRC_PATH)/tests/ref/fate/vp9-05-resize

+FATE_VP9-$(call FRAMEMD5, MATROSKA, VP9, TRIM_BSF) += fate-vp9-trim-preroll
+fate-vp9-trim-preroll: CMD = framemd5 -bsf:v trim=start=133:preroll=1 -i $(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-10-show-existing-frame.webm
+
 fate-vp9-encparams: CMD = venc_data $(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-segmentation-aq-akiyo.webm 0 5
 FATE_SAMPLES_DUMP_DATA-$(call DEMDEC, MATROSKA, VP9) += fate-vp9-encparams

diff --git a/tests/ref/fate/vp9-trim-preroll b/tests/ref/fate/vp9-trim-preroll
new file mode 100644
index 0000000000..0d2b256b6a
--- /dev/null
+++ b/tests/ref/fate/vp9-trim-preroll
@@ -0,0 +1,20 @@
+#format: frame checksums
+#version: 2
+#hash: MD5
+#tb 0: 1/30
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 1/1
+#stream#, dts,        pts, duration,     size, hash
+0,          4,          4,        1,   152064, 4ed58a0ba93a5d97a232a50c5876cda2
+0,          6,          6,        1,   152064, a41f00034923e56ba51a0b598acc2e3a
+0,          7,          7,        1,   152064, 63fa55ae9535ccdf06d44cce8065dda6
+0,          8,          8,        1,   152064, a41f00034923e56ba51a0b598acc2e3a
+0,          9,          9,        1,   152064, 0e4b08e14d919edee2bbff2ecd47de57
+0,         11,         11,        1,   152064, 0e4b08e14d919edee2bbff2ecd47de57
+0,         12,         12,        1,   152064, 5d4af03fc3d410413ef2b5a6275528b7
+0,         13,         13,        1,   152064, 9e932915c67a789f6877e6d3f76d3649
+0,         14,         14,        1,   152064, 12f2e975c217e7ffcf334524e8acec35
+0,         15,         15,        1,   152064, 9e932915c67a789f6877e6d3f76d3649
+0,         16,         16,        1,   152064, 12f2e975c217e7ffcf334524e8acec35