Decrease confusion.
Showing the changes to doc/examples/decoding_encoding.c (1 of 1 file). Show all
Unified · Split
| @@ -491,9 +491,9 @@ static void video_decode_example(const char *outfilename, const char *filename) · 490 unmodified lines | |||
| 491 | { | 491 | { |
| 492 | AVCodec *codec; | 492 | AVCodec *codec; |
| 493 | AVCodecContext *c= NULL; | 493 | AVCodecContext *c= NULL; |
| 494 | int frame, got_picture, len; | 494 | int frame_count, got_frame, len; |
| 495 | FILE *f; | 495 | FILE *f; |
| 496 | AVFrame *picture; | 496 | AVFrame *frame; |
| 497 | uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; | 497 | uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; |
| 498 | char buf[1024]; | 498 | char buf[1024]; |
| 499 | AVPacket avpkt; | 499 | AVPacket avpkt; |
| @@ -537,13 +537,13 @@ static void video_decode_example(const char *outfilename, const char *filename) · 37 unmodified lines | |||
| 537 | exit(1); | 537 | exit(1); |
| 538 | } | 538 | } |
| 539 | 539 | ||
| 540 | picture = avcodec_alloc_frame(); | 540 | frame = avcodec_alloc_frame(); |
| 541 | if (!picture) { | 541 | if (!frame) { |
| 542 | fprintf(stderr, "Could not allocate video frame\n"); | 542 | fprintf(stderr, "Could not allocate video frame\n"); |
| 543 | exit(1); | 543 | exit(1); |
| 544 | } | 544 | } |
| 545 | 545 | ||
| 546 | frame = 0; | 546 | frame_count = 0; |
| 547 | for(;;) { | 547 | for(;;) { |
| 548 | avpkt.size = fread(inbuf, 1, INBUF_SIZE, f); | 548 | avpkt.size = fread(inbuf, 1, INBUF_SIZE, f); |
| 549 | if (avpkt.size == 0) | 549 | if (avpkt.size == 0) |
| @@ -566,21 +566,21 @@ static void video_decode_example(const char *outfilename, const char *filename) · 16 unmodified lines | |||
| 566 | feed decoder and see if it could decode a frame */ | 566 | feed decoder and see if it could decode a frame */ |
| 567 | avpkt.data = inbuf; | 567 | avpkt.data = inbuf; |
| 568 | while (avpkt.size > 0) { | 568 | while (avpkt.size > 0) { |
| 569 | len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); | 569 | len = avcodec_decode_video2(c, frame, &got_frame, &avpkt); |
| 570 | if (len < 0) { | 570 | if (len < 0) { |
| 571 | fprintf(stderr, "Error while decoding frame %d\n", frame); | 571 | fprintf(stderr, "Error while decoding frame %d\n", frame_count); |
| 572 | exit(1); | 572 | exit(1); |
| 573 | } | 573 | } |
| 574 | if (got_picture) { | 574 | if (got_frame) { |
| 575 | printf("Saving frame %3d\n", frame); | 575 | printf("Saving frame %3d\n", frame_count); |
| 576 | fflush(stdout); | 576 | fflush(stdout); |
| 577 | 577 | ||
| 578 | /* the picture is allocated by the decoder. no need to | 578 | /* the picture is allocated by the decoder. no need to |
| 579 | free it */ | 579 | free it */ |
| 580 | snprintf(buf, sizeof(buf), outfilename, frame); | 580 | snprintf(buf, sizeof(buf), outfilename, frame_count); |
| 581 | pgm_save(picture->data[0], picture->linesize[0], | 581 | pgm_save(frame->data[0], frame->linesize[0], |
| 582 | c->width, c->height, buf); | 582 | c->width, c->height, buf); |
| 583 | frame++; | 583 | frame_count++; |
| 584 | } | 584 | } |
| 585 | avpkt.size -= len; | 585 | avpkt.size -= len; |
| 586 | avpkt.data += len; | 586 | avpkt.data += len; |
| @@ -592,24 +592,24 @@ static void video_decode_example(const char *outfilename, const char *filename) · 5 unmodified lines | |||
| 592 | chance to get the last frame of the video */ | 592 | chance to get the last frame of the video */ |
| 593 | avpkt.data = NULL; | 593 | avpkt.data = NULL; |
| 594 | avpkt.size = 0; | 594 | avpkt.size = 0; |
| 595 | len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); | 595 | len = avcodec_decode_video2(c, frame, &got_frame, &avpkt); |
| 596 | if (got_picture) { | 596 | if (got_frame) { |
| 597 | printf("Saving last frame %3d\n", frame); | 597 | printf("Saving last frame %3d\n", frame_count); |
| 598 | fflush(stdout); | 598 | fflush(stdout); |
| 599 | 599 | ||
| 600 | /* the picture is allocated by the decoder. no need to | 600 | /* the picture is allocated by the decoder. no need to |
| 601 | free it */ | 601 | free it */ |
| 602 | snprintf(buf, sizeof(buf), outfilename, frame); | 602 | snprintf(buf, sizeof(buf), outfilename, frame_count); |
| 603 | pgm_save(picture->data[0], picture->linesize[0], | 603 | pgm_save(frame->data[0], frame->linesize[0], |
| 604 | c->width, c->height, buf); | 604 | c->width, c->height, buf); |
| 605 | frame++; | 605 | frame_count++; |
| 606 | } | 606 | } |
| 607 | 607 | ||
| 608 | fclose(f); | 608 | fclose(f); |
| 609 | 609 | ||
| 610 | avcodec_close(c); | 610 | avcodec_close(c); |
| 611 | av_free(c); | 611 | av_free(c); |
| 612 | avcodec_free_frame(&picture); | 612 | avcodec_free_frame(&frame); |
| 613 | printf("\n"); | 613 | printf("\n"); |
| 614 | } | 614 | } |
| 615 | 615 | ||