[FFmpeg-devel] [PATCH] examples/decoding_encoding: re-organize frame configuration code

Stefano Sabatini stefasab at gmail.com
Tue Aug 21 20:54:20 CEST 2012


Put the relevant code in one chunk, also check for frame allocation
failures.
---
 doc/examples/decoding_encoding.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/doc/examples/decoding_encoding.c b/doc/examples/decoding_encoding.c
index 288432f..a6fed20 100644
--- a/doc/examples/decoding_encoding.c
+++ b/doc/examples/decoding_encoding.c
@@ -332,7 +332,6 @@ static void video_encode_example(const char *filename, int codec_id)
     }
 
     c = avcodec_alloc_context3(codec);
-    picture= avcodec_alloc_frame();
 
     /* put sample parameters */
     c->bit_rate = 400000;
@@ -360,6 +359,15 @@ static void video_encode_example(const char *filename, int codec_id)
         exit(1);
     }
 
+    picture = avcodec_alloc_frame();
+    if (!picture) {
+        fprintf(stderr, "Could not allocate frame\n");
+        exit(1);
+    }
+    picture->format = c->pix_fmt;
+    picture->width  = c->width;
+    picture->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(picture->data, picture->linesize, c->width, c->height,
@@ -369,10 +377,6 @@ static void video_encode_example(const char *filename, int codec_id)
         exit(1);
     }
 
-    picture->format = c->pix_fmt;
-    picture->width  = c->width;
-    picture->height = c->height;
-
     /* encode 1 second of video */
     for(i=0;i<25;i++) {
         av_init_packet(&pkt);
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list