aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-08-21 20:51:17 +0200
committerStefano Sabatini <stefasab@gmail.com>2012-08-22 11:54:24 +0200
commit535df748c5043bac6b03e598cfa93160ecce8383 (patch)
tree18028a5a4629ad3ad6581be9c589cbfd98198a90
parent780bf7595eaf76215bd2a5c6ea10004e4ca80ea2 (diff)
downloadffmpeg-535df748c5043bac6b03e598cfa93160ecce8383.tar.gz
examples/decoding_encoding: re-organize frame configuration code
Put the relevant code in one chunk, also check for frame allocation failures.
-rw-r--r--doc/examples/decoding_encoding.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/doc/examples/decoding_encoding.c b/doc/examples/decoding_encoding.c
index 288432f52c..d41f1fd1c5 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 video 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);
@@ -483,8 +487,6 @@ static void video_decode_example(const char *outfilename, const char *filename)
}
c = avcodec_alloc_context3(codec);
- picture= avcodec_alloc_frame();
-
if(codec->capabilities&CODEC_CAP_TRUNCATED)
c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */
@@ -506,6 +508,12 @@ static void video_decode_example(const char *outfilename, const char *filename)
exit(1);
}
+ picture = avcodec_alloc_frame();
+ if (!picture) {
+ fprintf(stderr, "Could not allocate video frame\n");
+ exit(1);
+ }
+
frame = 0;
for(;;) {
avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);