Commit 986bab2b47 for ffmpeg

commit 986bab2b47540c3d45d1299a40a3b103b344323c
Author: Michael Niedermayer <michael@niedermayer.cc>
Date:   Sun Nov 1 20:17:44 2026 +0000

    avcodec/pthread_frame: stop draining after thread context update failure

    A failed update_thread_context() leaves the worker indices unchanged.
    During draining, repeated receive_frame() calls then retry the same
    empty packet indefinitely. Mark draining complete after reporting the
    error once, and return EOF on subsequent calls.

    Fixes: #25626
    Reported-by: waroad
    Assisted-by: Fairy

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 8e88dda2ce..5b1d1f58f6 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -529,6 +529,10 @@ static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx,
             (codec->capabilities & AV_CODEC_CAP_DELAY)) {
             ret = update_context_from_thread(p->avctx, prev_thread->avctx, 0);
             if (ret) {
+                /* No packet was submitted and the thread indices did not advance,
+                 * so retrying the drain packet can repeat this error forever. */
+                if (user_avctx->internal->draining)
+                    user_avctx->internal->draining_done = 1;
                 pthread_mutex_unlock(&p->mutex);
                 return ret;
             }
@@ -562,6 +566,11 @@ int ff_thread_receive_frame(AVCodecContext *avctx, AVFrame *frame, unsigned flag
      * go forward while we are in this function */
     async_unlock(fctx);

+    if (avctx->internal->draining_done) {
+        ret = AVERROR_EOF;
+        goto finish;
+    }
+
     /* submit packets to threads while there are no buffered results to return */
     while (!fctx->df.nb_f && !fctx->result) {
         PerThreadContext *p;