1 diff --git a/libavcodec/encode.c b/libavcodec/encode_fprint.c
2 index 89df523..cca0cc1 100644
3 --- a/libavcodec/encode.c
4 +++ b/libavcodec/encode_fprint.c
5 @@ -191,7 +191,7 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
9 - if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
10 + if (avci->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
11 (avci->frame_thread_encoder && avctx->active_thread_type & FF_THREAD_FRAME)))
14 @@ -246,8 +246,10 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
18 - if (avci->draining && !got_packet)
19 + if (avci->draining && !got_packet) {
21 avci->draining_done = 1;
25 if (ret < 0 || !got_packet)
26 @@ -372,10 +374,16 @@ int attribute_align_arg avcodec_send_frame(AVCodecContext *avctx, const AVFrame
30 - if (avci->buffer_frame->data[0])
31 + if (avci->buffer_frame->data[0]) {
34 + av_frame_unref(avci->buffer_frame);
36 return AVERROR(EAGAIN);
43 ret = encode_send_frame_internal(avctx, frame);