[FFmpeg-devel] [PATCH] examples/decode_video: flush parser to fix missing frame

quinkblack at foxmail.com quinkblack at foxmail.com
Tue Aug 18 03:04:12 EEST 2020


From: Zhao Zhili <quinkblack at foxmail.com>

To reproduce, run decode_video with a single frame sample. No frame
was decoded before the patch.
---
 doc/examples/decode_video.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c
index 169188a4b9..ba753c6dc1 100644
--- a/doc/examples/decode_video.c
+++ b/doc/examples/decode_video.c
@@ -92,6 +92,7 @@ int main(int argc, char **argv)
     uint8_t *data;
     size_t   data_size;
     int ret;
+    int eof;
     AVPacket *pkt;
 
     if (argc <= 2) {
@@ -150,15 +151,14 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    while (!feof(f)) {
+    do {
         /* read raw data from the input file */
         data_size = fread(inbuf, 1, INBUF_SIZE, f);
-        if (!data_size)
-            break;
+        eof = !data_size;
 
         /* use the parser to split the data into frames */
         data = inbuf;
-        while (data_size > 0) {
+        while (data_size > 0 || eof) {
             ret = av_parser_parse2(parser, c, &pkt->data, &pkt->size,
                                    data, data_size, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);
             if (ret < 0) {
@@ -170,8 +170,10 @@ int main(int argc, char **argv)
 
             if (pkt->size)
                 decode(c, frame, pkt, outfilename);
+            if (eof)
+                break;
         }
-    }
+    } while (!eof);
 
     /* flush the decoder */
     decode(c, frame, NULL, outfilename);
-- 
2.28.0



More information about the ffmpeg-devel mailing list