diff mbox series

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

Message ID tencent_609A2E9F73AB634ED670392DD89A63400008@qq.com
State Superseded
Headers show
Series [FFmpeg-devel] examples/decode_video: flush parser to fix missing frame | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Zhao Zhili Aug. 18, 2020, 12:04 a.m. UTC
From: Zhao Zhili <quinkblack@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(-)

Comments

Guangxin Xu Sept. 9, 2020, 5:55 a.m. UTC | #1
On Tue, Aug 18, 2020 at 8:05 PM <quinkblack@foxmail.com> wrote:

> From: Zhao Zhili <quinkblack@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;
>
what if the parser cached more than one frame at the eof?

>          }
> -    }
> +    } while (!eof);
>
>      /* flush the decoder */
>      decode(c, frame, NULL, outfilename);
> --
> 2.28.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Zhao Zhili Sept. 23, 2020, 6:04 p.m. UTC | #2
> On Sep 9, 2020, at 1:55 PM, Guangxin Xu <oddstone@gmail.com> wrote:
> 
> 
> 
> On Tue, Aug 18, 2020 at 8:05 PM <quinkblack@foxmail.com <mailto:quinkblack@foxmail.com>> wrote:
> From: Zhao Zhili <quinkblack@foxmail.com <mailto:quinkblack@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;
> what if the parser cached more than one frame at the eof?

Good point. The internal loop should break only if (pkt->size == 0 && eof).

The updated patch:
http://ffmpeg.org/pipermail/ffmpeg-devel/2020-September/270251.html

>          }
> -    }
> +    } while (!eof);
> 
>      /* flush the decoder */
>      decode(c, frame, NULL, outfilename);
> -- 
> 2.28.0
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org <mailto:ffmpeg-devel-request@ffmpeg.org> with subject "unsubscribe".
diff mbox series

Patch

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);