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 && avctx->active_thread_type & FF_THREAD_FRAME)))
13 avpkt->flags |= avci->intra_only_flag;
16 - if (avci->draining && !got_packet)
17 + if (avci->draining && !got_packet) {
19 avci->draining_done = 1;
23 if (ret < 0 || !got_packet)
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);