[Libav-user] Correct way of freeing an AVFrame coming from avcodec_decode_video2

wm4 nfxjfg at googlemail.com
Sat Jul 5 17:35:37 CEST 2014


On Fri, 4 Jul 2014 16:09:53 +0200
Info || Non-Lethal Applications <info at non-lethal-applications.com>
wrote:

> Hey guys, 
> 
> I’m creating a recording application and I have an incoming frame which I’d like to convert to JPEG without writing it to a movie file.
> However, I need to use libav’s V210 decoder before creating the JPEG data.
> 
> I’m getting a memory leak in this code:
> 
> AVPacket pkt;
> av_init_packet(&pkt);
>             
> pkt.flags |= AV_PKT_FLAG_KEY;
> pkt.stream_index  = 0;
> pkt.data = imgData;
> pkt.size = ...
>     
> int gotPctr = 0;
>     
> AVFrame* frameGrabFrame = av_frame_alloc();
> avcodec_decode_video2(_pV210CodecCtxFrameGrab, frameGrabFrame, &gotPctr, &pkt);
>     
> I get a memory consumption increase of about 13 MB after the avcodec_decode call.
> However, I can’t manage to free the memory. I already tried without success:
> 
>     av_free_packet(&pkt);
>     av_frame_unref(frameGrabFrame);
>     av_frame_free(&frameGrabFrame);

This should be correct. av_frame_free() already calls av_frame_unref(),
but on the other hand calling av_frame_unref() multiple time is
perfectly ok.

> 
> I’m not using reference counting by the way.
> I’m sure that’s a dumb one … sorry for that.
> 
> Any advice appreciated!
> Thanks!


More information about the Libav-user mailing list