]> git.sesse.net Git - ffmpeg/commitdiff
examples/muxing: simplify alloc_picture()
authorStefano Sabatini <stefasab@gmail.com>
Fri, 3 Aug 2012 15:51:00 +0000 (17:51 +0200)
committerStefano Sabatini <stefasab@gmail.com>
Sat, 4 Aug 2012 22:26:39 +0000 (00:26 +0200)
Use avpicture_alloc() high level function.

doc/examples/muxing.c

index a24c447a96f7be65e0b59889f0888f89d359ddb6..ca5e107db3561ed8c7afad66d319f7ad3473d95d 100644 (file)
@@ -245,21 +245,9 @@ static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id)
 
 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;
 }