Merge commit '728ea23cce07467b732f538c87c13da13dd6dcf3'

* commit '728ea23cce07467b732f538c87c13da13dd6dcf3':
  examples/decode_video: switch to the new decoding API

Merged-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2017-04-04 14:41:23 -03:00
commit 52bce9a13d

View File

@ -52,28 +52,31 @@ static void decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket *pkt,
const char *filename) const char *filename)
{ {
char buf[1024]; char buf[1024];
int ret, got_picture; int ret;
while (pkt->size > 0) { ret = avcodec_send_packet(dec_ctx, pkt);
ret = avcodec_decode_video2(dec_ctx, frame, &got_picture, pkt); if (ret < 0) {
if (ret < 0) { fprintf(stderr, "Error sending a packet for decoding\n");
fprintf(stderr, "Error while decoding frame %d\n", dec_ctx->frame_number); exit(1);
}
while (ret >= 0) {
ret = avcodec_receive_frame(dec_ctx, frame);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
return;
else if (ret < 0) {
fprintf(stderr, "Error during decoding\n");
exit(1); exit(1);
} }
if (got_picture) {
printf("saving frame %3d\n", dec_ctx->frame_number);
fflush(stdout);
/* the picture is allocated by the decoder. no need to printf("saving frame %3d\n", dec_ctx->frame_number);
free it */ fflush(stdout);
snprintf(buf, sizeof(buf), filename, dec_ctx->frame_number);
pgm_save(frame->data[0], frame->linesize[0], /* the picture is allocated by the decoder. no need to
frame->width, frame->height, buf); free it */
} snprintf(buf, sizeof(buf), filename, dec_ctx->frame_number);
if (pkt->data) { pgm_save(frame->data[0], frame->linesize[0],
pkt->size -= ret; frame->width, frame->height, buf);
pkt->data += ret;
}
} }
} }
@ -170,9 +173,7 @@ int main(int argc, char **argv)
} }
/* flush the decoder */ /* flush the decoder */
avpkt.data = NULL; decode(c, frame, NULL, outfilename);
avpkt.size = 0;
decode(c, frame, &avpkt, outfilename);
fclose(f); fclose(f);