[Libav-user] Basic problem : memory leak when playing several movies

Fulbert Boussaton 42 at flubb.net
Mon Sep 16 14:40:37 CEST 2013


Very informative : I didn't know AVPicture had a bad rep.

I'll check it out.

Thanks.


On Sep 13, 2013, at 12:47, wm4 <nfxjfg at googlemail.com> wrote:

> On Thu, 12 Sep 2013 14:46:31 +0200
> Fulbert Boussaton <42 at flubb.net> wrote:
> 
>> AVFormatContext*	Ctx;
>> avformat_open_input(&Ctx, <...>, NULL, &Options);
>> avformat_find_stream_info(Ctx, NULL);
>> AVCodecContext* VCodecCtx = Ctx->streams[0]->codec;
>> AVCodec* TargetVideoCodec = avcodec_find_decoder(VCodecCtx->codec_id);
>> avcodec_open2(VCodecCtx, TargetVideoCodec, NULL);
>> AVFrame* TargetFrame = avcodec_alloc_frame();
>> AVFrame* TargetFrameRGB = avcodec_alloc_frame();
>> int FrameSizeInBytes = avpicture_get_size(PIX_FMT_RGB24, VCodecCtx->width, VCodecCtx->height);
>> uint8_t* FrameBuffer = (uint8_t*) av_malloc(FrameSizeInBytes);
>> avpicture_fill((AVPicture*) TargetFrameRGB, FrameBuffer, PIX_FMT_RGB24, VCodecCtx->width, VCodecCtx->height);
>> struct SwsContext* ScaleCtx = sws_getContext(VCodecCtx->width, VCodecCtx->height, VCodecCtx->pix_fmt, VCodecCtx->width, VCodecCtx->height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
>> 
>> And here are the functions I call to release all the previous structures :
>> 
>> sws_freeContext(ScaleCtx);
>> avpicture_free((AVPicture*)TargetFrameRGB);
>> av_free(FrameBuffer);
>> avcodec_free_frame(&TargetFrame);
>> avcodec_free_frame(&TargetFrameRGB);
>> avcodec_close(VCodecCtx);
>> avformat_close_input(&Ctx);
> 
> This all looks very wrong. I'd just stick to the AVFrame API, and not
> touch AVPicture. In some cases, you cast AVFrame to AVPicture, which
> only works by coincidence. (I'm not sure if it's possibly supposed to
> work - as far as I'm concerned AVPicture is ridiculous. You can get
> everything done without using AVPicture at all.)
> 
> See libavutil/frame.h.
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130916/a7b999e6/attachment.html>


More information about the Libav-user mailing list