1 --- a/libavcodec/encode.c
2 +++ b/libavcodec/encode.c
7 - if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
8 + if (avci->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
9 avci->frame_thread_encoder))
13 ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);
16 - if (avci->draining && !got_packet)
17 + if (avci->draining && !got_packet) {
19 avci->draining_done = 1;
28 - if (avci->buffer_frame->buf[0])
29 + if (avci->buffer_frame->buf[0]) {
32 + av_frame_unref(avci->buffer_frame);
34 return AVERROR(EAGAIN);
41 ret = encode_send_frame_internal(avctx, frame);