[FFmpeg-devel] About avpicture_alloc (deprecate?)

Cyril Russo stage.nexvision
Sun May 2 19:31:44 CEST 2010


Le 02/05/2010 17:57, Reimar D?ffinger a ?crit :
>
> I think you are confusing it with avcodec_alloc_frame.
> Which is basically the reason I'd like to change it since I get
> the suspicion a lot of people confuse the two.
> Given the signature of
> int avpicture_alloc(AVPicture *picture, enum PixelFormat pix_fmt, int width, int height)
> it doesn't work at all for that purpose.
>
>    
As soon as you use swscale, you need it.
avcodec_alloc_frame allocate the frame structure but not the "data" 
buffer, while avpicture_alloc does.

So unless you want people starting to allocate data[0] et al, by 
themselves (and doing bad thing with alignment since it's very hard to 
find out the required stride for decoder, see issue1909)

I'm almost sure it's linked with the other question about improving the 
documentation, and you're probably seing that there is an issue.

I agree both function sounds similar, which is confusing.
What even more confusing, is that avcodec_alloc_frame is required for 
avcodec_decode_video.
That is:
     AVFrame frame;
     avcodec_decode_video2(context, &frame, .... // Might crash, it's 
confusing since the doc might say that it allocates frame

But this leaks:
     AVFrame frame;
     avpicture_alloc((AVPicture*)&frame, pix_fmt, width, height);
     avcodec_decode_video2(context, &frame, .... // Leaks

This is good:
     AVFrame * frame = NULL;
     frame = avcodec_alloc_frame();
     avcodec_decode_video2(context, frame, .... // Should work

Initially, I've tried to say in the avcodec_decode_video dox that 
calling avpicture_alloc beforehand was to avoid.
For me, the option would probably to render picture & frame not binary 
compatible, so casting from any other is not possible. That way, when 
you deal with a AVFrame, you call x_frame functions, and when you deal 
with picture, you call x_picture functions.
Regards,
Cyril




More information about the ffmpeg-devel mailing list