History

examples/decoding_encoding: re-organize frame configuration code

Put the relevant code in one chunk, also check for frame allocation failures.

Stefano Sabatini committed 14 years ago

Commit 535df741 parent 780bf751 file · +15 −7Browse files

Showing the changes to doc/examples/decoding_encoding.c (1 of 1 file). Show all

Unified · Split

doc/examples/decoding_encoding.c+15−7
@@ -332,7 +332,6 @@ static void video_encode_example(const char *filename, int codec_id) · 331 unmodified lines
332332 }
333333
334334 c = avcodec_alloc_context3(codec);
335− picture= avcodec_alloc_frame();
336335
337336 /* put sample parameters */
338337 c->bit_rate = 400000;
@@ -360,6 +359,15 @@ static void video_encode_example(const char *filename, int codec_id) · 21 unmodified lines
360359 exit(1);
361360 }
362361
362+ picture = avcodec_alloc_frame();
363+ if (!picture) {
364+ fprintf(stderr, "Could not allocate video frame\n");
365+ exit(1);
366+ }
367+ picture->format = c->pix_fmt;
368+ picture->width = c->width;
369+ picture->height = c->height;
370+
363371 /* the image can be allocated by any means and av_image_alloc() is
364372 * just the most convenient way if av_malloc() is to be used */
365373 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) · 3 unmodified lines
369377 exit(1);
370378 }
371379
372− picture->format = c->pix_fmt;
373− picture->width = c->width;
374− picture->height = c->height;
375−
376380 /* encode 1 second of video */
377381 for(i=0;i<25;i++) {
378382 av_init_packet(&pkt);
@@ -483,8 +487,6 @@ static void video_decode_example(const char *outfilename, const char *filename) · 104 unmodified lines
483487 }
484488
485489 c = avcodec_alloc_context3(codec);
486− picture= avcodec_alloc_frame();
487−
488490 if(codec->capabilities&CODEC_CAP_TRUNCATED)
489491 c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */
490492
@@ -506,6 +508,12 @@ static void video_decode_example(const char *outfilename, const char *filename) · 15 unmodified lines
506508 exit(1);
507509 }
508510
511+ picture = avcodec_alloc_frame();
512+ if (!picture) {
513+ fprintf(stderr, "Could not allocate video frame\n");
514+ exit(1);
515+ }
516+
509517 frame = 0;
510518 for(;;) {
511519 avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t