[FFmpeg-devel] [PATCH] libxvid: Create extradata in init using a dummy frame

Michael Niedermayer michael at niedermayer.cc
Sun Apr 3 20:59:54 CEST 2016


On Sun, Apr 03, 2016 at 12:57:28PM -0400, Derek Buitenhuis wrote:
> Modifying global header extradata in encode_frame is an API violation
> and only happens to work currently because mov writes its header
> at the end of the file.
> 
> Heavily based off of a patch from 2012.
> 
> Original-by: Nicolas George <george at nsup.org>
> Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
> ---
>  libavcodec/libxvid.c | 37 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 37 insertions(+)
> 
> diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c
> index 76e725e..b48568f 100644
> --- a/libavcodec/libxvid.c
> +++ b/libavcodec/libxvid.c
> @@ -96,6 +96,9 @@ struct xvid_ff_pass1 {
>  };
>  
>  static int xvid_encode_close(AVCodecContext *avctx);
> +static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
> +                             const AVFrame *picture, int *got_packet);
> +
>  
>  /*
>   * Xvid 2-Pass Kludge Section
> @@ -707,6 +710,40 @@ FF_ENABLE_DEPRECATION_WARNINGS
>  
>      av_assert0(xvid_enc_create.num_plugins + (!!x->ssim) + (!!x->variance_aq) + (!!x->lumi_aq) <= FF_ARRAY_ELEMS(plugins));
>  
> +    /* Encode a dummy frame to get the extradata immediately */
> +    if (x->quicktime_format) {
> +        AVFrame *picture;
> +        AVPacket packet;
> +        int size, got_packet, ret;
> +
> +        av_init_packet(&packet);
> +
> +        picture = av_frame_alloc();
> +        if (!picture)
> +            return AVERROR(ENOMEM);
> +
> +        xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
> +        if( xerr ) {
> +            av_log(avctx, AV_LOG_ERROR, "Xvid: Could not create encoder reference\n");
> +            return -1;

maybe AVERROR_UNKNOWN or maybe theres a better code


> +        }
> +        x->encoder_handle = xvid_enc_create.handle;
> +        size = ((avctx->width + 1) & ~1) * ((avctx->height + 1) & ~1);
> +        picture->data[0] = av_malloc(size + size / 2);

> +        if (!picture->data[0])
> +            return AVERROR(ENOMEM);

leaks picture


> +        picture->data[1] = picture->data[0] + size;
> +        picture->data[2] = picture->data[1] + size / 4;
> +        memset(picture->data[0], 0, size);
> +        memset(picture->data[1], 128, size / 2);
> +        ret = xvid_encode_frame(avctx, &packet, picture, &got_packet);
> +        if (!ret && got_packet)
> +            av_packet_unref(&packet);



> +        av_free(picture->data[0]);

> +        av_frame_unref(picture);

shouldnt this be av_frame_free() ?


> +        xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL);
> +    }
> +
>      /* Create encoder context */
>      xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
>      if (xerr) {
> -- 
> 2.8.0.rc3
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160403/52cffea6/attachment.sig>


More information about the ffmpeg-devel mailing list