summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2017-04-04 14:41:23 -0300
committerJames Almer <jamrial@gmail.com>2017-04-04 14:41:23 -0300
commit52bce9a13ddca52921c8a32ffcdd2d97b15d0f4d (patch)
tree3b773d93977f81c9cb07e3db3abf4b530c080a56 /doc
parentfddd6af45cfdb228cd34c36210a8afd39757a6c8 (diff)
parent728ea23cce07467b732f538c87c13da13dd6dcf3 (diff)
Merge commit '728ea23cce07467b732f538c87c13da13dd6dcf3'
* commit '728ea23cce07467b732f538c87c13da13dd6dcf3': examples/decode_video: switch to the new decoding API Merged-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/decode_video.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c
index 980add305f..5c1c42c967 100644
--- a/doc/examples/decode_video.c
+++ b/doc/examples/decode_video.c
@@ -52,28 +52,31 @@ static void decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket *pkt,
const char *filename)
{
char buf[1024];
- int ret, got_picture;
+ int ret;
+
+ ret = avcodec_send_packet(dec_ctx, pkt);
+ if (ret < 0) {
+ fprintf(stderr, "Error sending a packet for decoding\n");
+ exit(1);
+ }
- while (pkt->size > 0) {
- ret = avcodec_decode_video2(dec_ctx, frame, &got_picture, pkt);
- if (ret < 0) {
- fprintf(stderr, "Error while decoding frame %d\n", dec_ctx->frame_number);
+ 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);
}
- if (got_picture) {
- printf("saving frame %3d\n", dec_ctx->frame_number);
- fflush(stdout);
-
- /* the picture is allocated by the decoder. no need to
- free it */
- snprintf(buf, sizeof(buf), filename, dec_ctx->frame_number);
- pgm_save(frame->data[0], frame->linesize[0],
- frame->width, frame->height, buf);
- }
- if (pkt->data) {
- pkt->size -= ret;
- pkt->data += ret;
- }
+
+ printf("saving frame %3d\n", dec_ctx->frame_number);
+ fflush(stdout);
+
+ /* the picture is allocated by the decoder. no need to
+ free it */
+ snprintf(buf, sizeof(buf), filename, dec_ctx->frame_number);
+ pgm_save(frame->data[0], frame->linesize[0],
+ frame->width, frame->height, buf);
}
}
@@ -170,9 +173,7 @@ int main(int argc, char **argv)
}
/* flush the decoder */
- avpkt.data = NULL;
- avpkt.size = 0;
- decode(c, frame, &avpkt, outfilename);
+ decode(c, frame, NULL, outfilename);
fclose(f);