[FFmpeg-devel] [PATCH] avcodec/utils: Allocate dummy codec_frame for video encoders which do not allocate one

Andreas Cadhalpun andreas.cadhalpun at googlemail.com
Mon Feb 23 18:19:39 CET 2015


On 23.02.2015 17:19, Michael Niedermayer wrote:
> This should allow simplifying many encoders
>
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>   libavcodec/utils.c |   12 ++++++++++++
>   1 file changed, 12 insertions(+)
>
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index c5e6300..c6d588a 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -1695,6 +1695,16 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
>           av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
>       }
>
> +    if (av_codec_is_encoder(avctx->codec) &&
> +        avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
> +        !avctx->coded_frame) {
> +        avctx->coded_frame = av_frame_alloc();
> +        if (avctx->coded_frame) {
> +            av_assert0(avctx->coded_frame->key_frame);
> +            avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
> +        }
> +    }
> +
>   end:
>       ff_unlock_avcodec();
>       if (options) {
> @@ -2852,6 +2862,8 @@ av_cold int avcodec_close(AVCodecContext *avctx)
>           av_freep(&avctx->internal->hwaccel_priv_data);
>
>           av_freep(&avctx->internal);
> +        if (av_codec_is_encoder(avctx->codec))
> +            av_frame_free(&avctx->coded_frame);
>       }

This probably doesn't work, be cause a few lines above is:
         avctx->coded_frame = NULL;

Moving that down should make it work.

Best regards,
Andreas


More information about the ffmpeg-devel mailing list