static AVFrame *alloc_picture(enum PixelFormat pix_fmt, int width, int height)
{
- AVFrame *picture;
- uint8_t *picture_buf;
- int size;
-
- picture = avcodec_alloc_frame();
- if (!picture)
- return NULL;
- size = avpicture_get_size(pix_fmt, width, height);
- picture_buf = av_malloc(size);
- if (!picture_buf) {
- av_free(picture);
- return NULL;
- }
- avpicture_fill((AVPicture *)picture, picture_buf,
- pix_fmt, width, height);
+ AVFrame *picture = avcodec_alloc_frame();
+ if (!picture || avpicture_alloc((AVPicture *)picture, pix_fmt, width, height) < 0)
+ av_freep(&picture);
return picture;
}