Commit 303510f9d1 for ffmpeg

commit 303510f9d1fe19bcae440df0d940f33616d93bf5
Author: hayateppp <>
Date:   Thu Oct 22 09:17:32 2026 +0000

    avcodec/cuviddec: drain queued output before parsing more input

    A queued display entry holds a decode surface index, not a copy of its
    pixels. Parsing another packet can reuse that surface before the entry
    is mapped, associating a later image with the queued timestamp. The
    queue occupancy check does not protect individual surface lifetimes.

    Consume queued output before fetching another packet. In particular,
    this drains both deinterlaced fields before submitting further input.

    A generated 120-frame interlaced H.264 stream decoded with -deint bob
    produces 157 incorrect images out of 240 on an RTX 5090. With this guard,
    all 240 images match the software-decoded, spatially constant source
    frames, and diagnostic logging no longer observes queued surface reuse.

    Based on the candidate fix provided by hayateppp in issue #25210.
    The original report's private inputs remain untested here.

    Assisted-by: Fairy

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 14744cf067..9bc174d2ee 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -913,7 +913,8 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
                 return ret;
         }

-        if (!cuvid_is_buffer_full(avctx)) {
+        // Consume queued output before parsing can reuse its decode surfaces.
+        if (!av_fifo_can_read(ctx->frame_queue) && !cuvid_is_buffer_full(avctx)) {
             AVPacket *const pkt = ctx->pkt;
             ret = ff_decode_get_packet(avctx, pkt);
             if (ret < 0 && ret != AVERROR_EOF)