Commit d3b8d56e authored by Stefano Sabatini's avatar Stefano Sabatini

examples/decoding_encoding: prefer 'frame' over 'picture' for an AVFrame

Decrease confusion.
parent dd84efe3
...@@ -491,9 +491,9 @@ static void video_decode_example(const char *outfilename, const char *filename) ...@@ -491,9 +491,9 @@ static void video_decode_example(const char *outfilename, const char *filename)
{ {
AVCodec *codec; AVCodec *codec;
AVCodecContext *c= NULL; AVCodecContext *c= NULL;
int frame, got_picture, len; int frame_count, got_frame, len;
FILE *f; FILE *f;
AVFrame *picture; AVFrame *frame;
uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
char buf[1024]; char buf[1024];
AVPacket avpkt; AVPacket avpkt;
...@@ -537,13 +537,13 @@ static void video_decode_example(const char *outfilename, const char *filename) ...@@ -537,13 +537,13 @@ static void video_decode_example(const char *outfilename, const char *filename)
exit(1); exit(1);
} }
picture = avcodec_alloc_frame(); frame = avcodec_alloc_frame();
if (!picture) { if (!frame) {
fprintf(stderr, "Could not allocate video frame\n"); fprintf(stderr, "Could not allocate video frame\n");
exit(1); exit(1);
} }
frame = 0; frame_count = 0;
for(;;) { for(;;) {
avpkt.size = fread(inbuf, 1, INBUF_SIZE, f); avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);
if (avpkt.size == 0) if (avpkt.size == 0)
...@@ -566,21 +566,21 @@ static void video_decode_example(const char *outfilename, const char *filename) ...@@ -566,21 +566,21 @@ static void video_decode_example(const char *outfilename, const char *filename)
feed decoder and see if it could decode a frame */ feed decoder and see if it could decode a frame */
avpkt.data = inbuf; avpkt.data = inbuf;
while (avpkt.size > 0) { while (avpkt.size > 0) {
len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); len = avcodec_decode_video2(c, frame, &got_frame, &avpkt);
if (len < 0) { if (len < 0) {
fprintf(stderr, "Error while decoding frame %d\n", frame); fprintf(stderr, "Error while decoding frame %d\n", frame_count);
exit(1); exit(1);
} }
if (got_picture) { if (got_frame) {
printf("Saving frame %3d\n", frame); printf("Saving frame %3d\n", frame_count);
fflush(stdout); fflush(stdout);
/* the picture is allocated by the decoder. no need to /* the picture is allocated by the decoder. no need to
free it */ free it */
snprintf(buf, sizeof(buf), outfilename, frame); snprintf(buf, sizeof(buf), outfilename, frame_count);
pgm_save(picture->data[0], picture->linesize[0], pgm_save(frame->data[0], frame->linesize[0],
c->width, c->height, buf); c->width, c->height, buf);
frame++; frame_count++;
} }
avpkt.size -= len; avpkt.size -= len;
avpkt.data += len; avpkt.data += len;
...@@ -592,24 +592,24 @@ static void video_decode_example(const char *outfilename, const char *filename) ...@@ -592,24 +592,24 @@ static void video_decode_example(const char *outfilename, const char *filename)
chance to get the last frame of the video */ chance to get the last frame of the video */
avpkt.data = NULL; avpkt.data = NULL;
avpkt.size = 0; avpkt.size = 0;
len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); len = avcodec_decode_video2(c, frame, &got_frame, &avpkt);
if (got_picture) { if (got_frame) {
printf("Saving last frame %3d\n", frame); printf("Saving last frame %3d\n", frame_count);
fflush(stdout); fflush(stdout);
/* the picture is allocated by the decoder. no need to /* the picture is allocated by the decoder. no need to
free it */ free it */
snprintf(buf, sizeof(buf), outfilename, frame); snprintf(buf, sizeof(buf), outfilename, frame_count);
pgm_save(picture->data[0], picture->linesize[0], pgm_save(frame->data[0], frame->linesize[0],
c->width, c->height, buf); c->width, c->height, buf);
frame++; frame_count++;
} }
fclose(f); fclose(f);
avcodec_close(c); avcodec_close(c);
av_free(c); av_free(c);
avcodec_free_frame(&picture); avcodec_free_frame(&frame);
printf("\n"); printf("\n");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment