diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c index 8411cc7582..7b6ec97d3b 100644 --- a/libavcodec/hw_base_encode.c +++ b/libavcodec/hw_base_encode.c @@ -440,16 +440,18 @@ static int hw_base_encode_send_frame(AVCodecContext *avctx, FFHWBaseEncodeContex goto fail; } - pic->recon_image = av_frame_alloc(); - if (!pic->recon_image) { - err = AVERROR(ENOMEM); - goto fail; - } + if (ctx->recon_frames_ref) { + pic->recon_image = av_frame_alloc(); + if (!pic->recon_image) { + err = AVERROR(ENOMEM); + goto fail; + } - err = av_hwframe_get_buffer(ctx->recon_frames_ref, pic->recon_image, 0); - if (err < 0) { - err = AVERROR(ENOMEM); - goto fail; + err = av_hwframe_get_buffer(ctx->recon_frames_ref, pic->recon_image, 0); + if (err < 0) { + err = AVERROR(ENOMEM); + goto fail; + } } pic->priv = av_mallocz(ctx->op->priv_size);