[FFmpeg-devel] Allocating and deallocating AVFrame & AVPicture

John Dexter jdxsolutions at gmail.com
Mon Feb 27 19:29:21 CET 2012


On 27 February 2012 18:24, Matthew Einhorn <moiein2000 at gmail.com> wrote:
> On Mon, Feb 27, 2012 at 12:22 PM, John Dexter <jdxsolutions at gmail.com> wrote:
>>
>> 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);
>> }
>>
>>
>
> avcodec_alloc_frame() allocates the frame, but not the buffer in which
> the pic would be stored. avpicture_alloc() allocates the actuall
> buffer (you can do similar with av_image_alloc()). So when freeing,
> av_free(pFrame) frees the frame not the buffer, so you also have to
> call av_free(pFrame.data[0]) before to free the buffer.
>


Thanks Matt.

Carl - your comment is a bit vague. Are you indirectly saying I should
have asked on the libav list instead? If so I probably shouldn't be on
this list at all if it's only for those working on ffmpeg itself!


More information about the ffmpeg-devel mailing list