[FFmpeg-devel] Allocating and deallocating AVFrame & AVPicture

John Dexter jdxsolutions at gmail.com
Mon Feb 27 18:22:01 CET 2012


I record rendered output of my 3D engine to video using ffmpeg libs.
I'm finding after a minute or so (a few hundred frames),
avpicture_alloc suddenly fails in my frame method:

bool frame( void *buf,unsigned int inWidth,unsigned int inHeight)
{
	AVFrame *pFrame = avcodec_alloc_frame();
	if (!pFrame) {
		error("Can't allocate memory for AVFrame");
		return false;
	}

    avcodec_get_frame_defaults(pFrame);
    if(avpicture_alloc((AVPicture*)pFrame, PIX_FMT_BGRA, inWidth, inHeight)<0)
	{
		error("Failed allocating frame in avpicture_alloc()");
		return false;
	}

.... //do other stuff

	av_free(pFrame);
}


My specific question - Right now I only call av_free(), should I be
freeing result of avpicture_alloc() explicitly as well? I assume this
is _probably_ the issue but am  a total noob with ffmpeg codebase.

More generally - should I be able to allocate my AVFrame and AVPicture
once and re-use? If so, anything special I need to watch out for? I
tried it but things were going weird and I wanted to check before
digging into it more.

Thanks,
John.


More information about the ffmpeg-devel mailing list