[FFmpeg-devel] [PATCH 2/4] lavc: add API for exporting reconstructed frames from encoders
James Almer
jamrial at gmail.com
Mon Jul 18 15:35:30 EEST 2022
On 7/17/2022 4:26 PM, Anton Khirnov wrote:
> diff --git a/libavcodec/encode.c b/libavcodec/encode.c
> index 1f39ab1a2f..f15309ce09 100644
> --- a/libavcodec/encode.c
> +++ b/libavcodec/encode.c
> @@ -594,6 +594,18 @@ int ff_encode_preinit(AVCodecContext *avctx)
> return AVERROR(ENOMEM);
> }
>
> + if ((avctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
> + if (!(avctx->codec->capabilities & AV_CODEC_CAP_ENCODER_RECON_FRAME)) {
> + av_log(avctx, AV_LOG_ERROR, "Reconstructed frame output requested "
> + "from an encoder not supporting it\n");
> + return AVERROR(ENOSYS);
> + }
> +
> + avci->recon_frame = av_frame_alloc();
> + if (!avci->recon_frame)
> + return AVERROR(ENOMEM);
> + }
> +
> return 0;
> }
>
> @@ -630,3 +642,16 @@ int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
>
> return 0;
> }
> +
> +int ff_encode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
> +{
> + AVCodecInternal *avci = avctx->internal;
> +
> + if (!avci->recon_frame)
> + return AVERROR(EINVAL);
> + if (!avci->recon_frame->buf[0])
> + return avci->draining_done ? AVERROR_EOF : AVERROR(EAGAIN);
> +
> + av_frame_move_ref(frame, avci->recon_frame);
The API for avcodec_receive_frame() mentions frame will be unref'd first
thing, so you should do that before even the recon_frame checks.
> + return 0;
> +}
More information about the ffmpeg-devel
mailing list