diff mbox series

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

Message ID tencent_1EA85C73E4336835DFA9092EACC551731105@qq.com
State New
Headers show
Series [FFmpeg-devel,v3] examples/decode_video: flush parser to fix missing frame
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Zhao Zhili April 1, 2021, 1:32 p.m. UTC
---
check EOF by "eof = !data_size && feof(f);"

 doc/examples/decode_video.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c
index 18ee90a6c0..2f779328a7 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 && feof(f);
 
         /* 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);
+            else if (eof)
+                break;
         }
-    }
+    } while (!eof);
 
     /* flush the decoder */
     decode(c, frame, NULL, outfilename);