[SCM] libav/experimental: output example: use the new AVFrame API for allocating the video frame

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Aug 10 16:03:37 UTC 2014


The following commit has been merged in the experimental branch:
commit 38d044429dabcd28928693240e955c6d4430cca9
Author: Anton Khirnov <anton at khirnov.net>
Date:   Mon Jun 16 13:20:51 2014 +0200

    output example: use the new AVFrame API for allocating the video frame

diff --git a/doc/examples/output.c b/doc/examples/output.c
index 0239791..52b01d0 100644
--- a/doc/examples/output.c
+++ b/doc/examples/output.c
@@ -234,20 +234,23 @@ static AVStream *add_video_stream(AVFormatContext *oc, enum AVCodecID codec_id)
 static AVFrame *alloc_picture(enum AVPixelFormat pix_fmt, int width, int height)
 {
     AVFrame *picture;
-    uint8_t *picture_buf;
-    int size;
+    int ret;
 
     picture = av_frame_alloc();
     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;
+
+    picture->format = pix_fmt;
+    picture->width  = width;
+    picture->height = height;
+
+    /* allocate the buffers for the frame data */
+    ret = av_frame_get_buffer(picture, 32);
+    if (ret < 0) {
+        fprintf(stderr, "Could not allocate frame data.\n");
+        exit(1);
     }
-    avpicture_fill((AVPicture *)picture, picture_buf,
-                   pix_fmt, width, height);
+
     return picture;
 }
 
@@ -287,7 +290,15 @@ static void open_video(AVFormatContext *oc, AVStream *st)
 static void fill_yuv_image(AVFrame *pict, int frame_index,
                            int width, int height)
 {
-    int x, y, i;
+    int x, y, i, ret;
+
+    /* when we pass a frame to the encoder, it may keep a reference to it
+     * internally;
+     * make sure we do not overwrite it here
+     */
+    ret = av_frame_make_writable(pict);
+    if (ret < 0)
+        exit(1);
 
     i = frame_index;
 
@@ -381,12 +392,8 @@ static void write_video_frame(AVFormatContext *oc, AVStream *st)
 static void close_video(AVFormatContext *oc, AVStream *st)
 {
     avcodec_close(st->codec);
-    av_free(picture->data[0]);
-    av_free(picture);
-    if (tmp_picture) {
-        av_free(tmp_picture->data[0]);
-        av_free(tmp_picture);
-    }
+    av_frame_free(&picture);
+    av_frame_free(&tmp_picture);
 }
 
 /**************************************************************/

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list