Patchwork examples/decoding_encoding: fix encoding when all frames got buffered.

login
register
mail settings
Submitter Michael Niedermayer
Date May 3, 2012, 11:14 a.m.
Message ID <20120503111447.F070D149E98@albiero.videolan.org>
Download mbox | patch
Permalink /patch/21074/
State New
Headers show

Comments

Michael Niedermayer - May 3, 2012, 11:14 a.m.
ffmpeg | branch: master | Michael Niedermayer <michaelni@gmx.at> | Thu May  3 12:25:17 2012 +0200| [28d37f71607bd63f7f09f9125a3e243179ebf9af] | committer: Michael Niedermayer

examples/decoding_encoding: fix encoding when all frames got buffered.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=28d37f71607bd63f7f09f9125a3e243179ebf9af
---

 doc/examples/decoding_encoding.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

Patch

diff --git a/doc/examples/decoding_encoding.c b/doc/examples/decoding_encoding.c
index 4b93b58..cb63294 100644
--- a/doc/examples/decoding_encoding.c
+++ b/doc/examples/decoding_encoding.c
@@ -215,6 +215,7 @@  static void video_encode_example(const char *filename, int codec_id)
     FILE *f;
     AVFrame *picture;
     uint8_t *outbuf;
+    int had_output=0;
 
     printf("Video encoding\n");
 
@@ -284,15 +285,17 @@  static void video_encode_example(const char *filename, int codec_id)
 
         /* encode the image */
         out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
+        had_output |= out_size;
         printf("encoding frame %3d (size=%5d)\n", i, out_size);
         fwrite(outbuf, 1, out_size, f);
     }
 
     /* get the delayed frames */
-    for(; out_size; i++) {
+    for(; out_size || !had_output; i++) {
         fflush(stdout);
 
         out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
+        had_output |= out_size;
         printf("write frame %3d (size=%5d)\n", i, out_size);
         fwrite(outbuf, 1, out_size, f);
     }