[FFmpeg-cvslog] Merge commit '5b4d7ac7ae5d821cfa6ab89f8eab4d31851ef32c'

Clément Bœsch git at videolan.org
Wed Mar 29 15:22:24 EEST 2017


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Wed Mar 29 14:20:25 2017 +0200| [58f24adc05b0ea47c3f7ed5cb9e8d5774e2fbaaf] | committer: Clément Bœsch

Merge commit '5b4d7ac7ae5d821cfa6ab89f8eab4d31851ef32c'

* commit '5b4d7ac7ae5d821cfa6ab89f8eab4d31851ef32c':
  examples/encode_video: use the AVFrame API for allocating the frame

Merged-by: Clément Bœsch <u at pkh.me>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=58f24adc05b0ea47c3f7ed5cb9e8d5774e2fbaaf
---

 doc/examples/encode_video.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/doc/examples/encode_video.c b/doc/examples/encode_video.c
index ba6f2bf..fc576e0 100644
--- a/doc/examples/encode_video.c
+++ b/doc/examples/encode_video.c
@@ -112,12 +112,9 @@ int main(int argc, char **argv)
     frame->width  = c->width;
     frame->height = c->height;
 
-    /* the image can be allocated by any means and av_image_alloc() is
-     * just the most convenient way if av_malloc() is to be used */
-    ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height,
-                         c->pix_fmt, 32);
+    ret = av_frame_get_buffer(frame, 32);
     if (ret < 0) {
-        fprintf(stderr, "Could not allocate raw picture buffer\n");
+        fprintf(stderr, "Could not allocate the video frame data\n");
         exit(1);
     }
 
@@ -128,6 +125,12 @@ int main(int argc, char **argv)
         pkt.size = 0;
 
         fflush(stdout);
+
+        /* make sure the frame data is writable */
+        ret = av_frame_make_writable(frame);
+        if (ret < 0)
+            exit(1);
+
         /* prepare a dummy image */
         /* Y */
         for (y = 0; y < c->height; y++) {
@@ -182,7 +185,6 @@ int main(int argc, char **argv)
     fclose(f);
 
     avcodec_free_context(&c);
-    av_freep(&frame->data[0]);
     av_frame_free(&frame);
 
     return 0;


======================================================================

diff --cc doc/examples/encode_video.c
index ba6f2bf,3fd2d56..fc576e0
--- a/doc/examples/encode_video.c
+++ b/doc/examples/encode_video.c
@@@ -103,21 -88,13 +103,18 @@@ int main(int argc, char **argv
          exit(1);
      }
  
 -    picture->format = c->pix_fmt;
 -    picture->width  = c->width;
 -    picture->height = c->height;
 +    frame = av_frame_alloc();
 +    if (!frame) {
 +        fprintf(stderr, "Could not allocate video frame\n");
 +        exit(1);
 +    }
 +    frame->format = c->pix_fmt;
 +    frame->width  = c->width;
 +    frame->height = c->height;
  
-     /* the image can be allocated by any means and av_image_alloc() is
-      * just the most convenient way if av_malloc() is to be used */
-     ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height,
-                          c->pix_fmt, 32);
 -    ret = av_frame_get_buffer(picture, 32);
++    ret = av_frame_get_buffer(frame, 32);
      if (ret < 0) {
-         fprintf(stderr, "Could not allocate raw picture buffer\n");
 -        fprintf(stderr, "could not alloc the frame data\n");
++        fprintf(stderr, "Could not allocate the video frame data\n");
          exit(1);
      }
  
@@@ -128,11 -105,17 +125,17 @@@
          pkt.size = 0;
  
          fflush(stdout);
+ 
+         /* make sure the frame data is writable */
 -        ret = av_frame_make_writable(picture);
++        ret = av_frame_make_writable(frame);
+         if (ret < 0)
+             exit(1);
+ 
          /* prepare a dummy image */
          /* Y */
 -        for(y=0;y<c->height;y++) {
 -            for(x=0;x<c->width;x++) {
 -                picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
 +        for (y = 0; y < c->height; y++) {
 +            for (x = 0; x < c->width; x++) {
 +                frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
              }
          }
  
@@@ -182,8 -165,7 +185,7 @@@
      fclose(f);
  
      avcodec_free_context(&c);
-     av_freep(&frame->data[0]);
 -    av_frame_free(&picture);
 +    av_frame_free(&frame);
  
      return 0;
  }



More information about the ffmpeg-cvslog mailing list