Re: [libav-devel] [PATCH 12/13] examples/decode_video: switch to the new decoding API

2016-11-15 Thread Luca Barbato
On 10/11/2016 16:51, Anton Khirnov wrote:
> ---
>  doc/examples/decode_video.c | 43 +++
>  1 file changed, 23 insertions(+), 20 deletions(-)
> 

Seems Ok.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 12/13] examples/decode_video: switch to the new decoding API

2016-11-10 Thread Anton Khirnov
---
 doc/examples/decode_video.c | 43 +++
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c
index 4c1068b..7414643 100644
--- a/doc/examples/decode_video.c
+++ b/doc/examples/decode_video.c
@@ -54,26 +54,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);
-}
-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);
 }
 }
 
@@ -161,9 +166,7 @@ int main(int argc, char **argv)
 }
 
 /* flush the decoder */
-avpkt.data = NULL;
-avpkt.size = 0;
-decode(c, picture, &avpkt, outfilename);
+decode(c, picture, NULL, outfilename);
 
 fclose(f);
 
-- 
2.0.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel