[libav-api] AVFrame memory management

Anton Khirnov anton at khirnov.net
Fri Aug 22 17:11:25 CEST 2014


On Wed, 20 Aug 2014 11:32:01 +0200, g kuczera <gkuczera at gmail.com> wrote:
> Hi Anton,
> My LibAV is new enough. But if I simply change the getPreparedFrame method
> to be like this:
> 
> AVFrame* getPreparedFrame(AVPixelFormat pPixelFormat, int pWidth /*= 320*/,
> int pHeight /*= 240*/)
> {
> AVFrame* tFrame = av_frame_alloc();
> tFrame->format = pPixelFormat;
> tFrame->width = pWidth;
> tFrame->height = pHeight;
> tFrame->nb_samples = 0; tFrame->channel_layout = 0;
> 
> if (!tFrame)
> {
> return NULL;
> }
> //Have to be set:
> //-format(pixel format for video, sample format for audio)
> //-width and height for video
> //-nb_samples and channel_layout for audio
> av_frame_get_buffer(tFrame, 0);
> 
> return tFrame;
> }
> 
> then passing this frame to sws_scale as the destination, results in the
> error message:
> 
> "[swscaler @ 00b42260] bad dst image pointers"
> 
> What do you think about that? Should anything has to be done before passing
> frame created in this way to sws_scale? Or maybe I should pass specific
> value as the "align" parameter?
> 

IIRC using 0 for align does not work for video (av_frame_get_buffer() should
return an error, check the return value). Use something like 32.

-- 
Anton Khirnov


More information about the libav-api mailing list