--- a/libavcodec/encode.c	2025-05-12 08:52:53.070539488 -0600
+++ b/libavcodec/encode.c	2025-05-12 08:40:22.831978565 -0600
@@ -306,7 +306,7 @@
     }
 
     if (!frame->buf[0]) {
-        if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
+        if (avci->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
               avci->frame_thread_encoder))
             return AVERROR_EOF;
 
@@ -325,8 +325,10 @@
         ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);
     }
 
-    if (avci->draining && !got_packet)
+    if (avci->draining && !got_packet) {
+       fflush(stderr);
         avci->draining_done = 1;
+    }
 
     return ret;
 }
@@ -501,10 +503,16 @@
     if (avci->draining)
         return AVERROR_EOF;
 
-    if (avci->buffer_frame->buf[0])
+    if (avci->buffer_frame->buf[0]) {
+        if (!frame) {
+           fflush(stderr);
+            av_frame_unref(avci->buffer_frame);
+       }
         return AVERROR(EAGAIN);
+    }
 
     if (!frame) {
+       fflush(stderr);
         avci->draining = 1;
     } else {
         ret = encode_send_frame_internal(avctx, frame);
