Message ID | tencent_0556FD9C82E08A5A9C35F381A834213ED509@qq.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,v2] examples/decode_video: flush parser to fix missing frame | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
Ping. I have got multiple users report about the issue when they use the example as a tutorial. > On Oct 12, 2020, at 12:47 AM, Zhao Zhili <quinkblack@foxmail.com> wrote: > > Ping for review. > >> On Sep 24, 2020, at 2:01 AM, Zhao Zhili <quinkblack@foxmail.com> wrote: >> >> 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 18ee90a6c0..9ce3531d63 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); >> + else if (eof) >> + break; >> } >> - } >> + } while (!eof); >> >> /* flush the decoder */ >> decode(c, frame, NULL, outfilename); >> -- >> 2.25.1 >> >> _______________________________________________ >> 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". >
On Thu, Sep 24, 2020 at 2:01 AM Zhao Zhili <quinkblack@foxmail.com> wrote: > > 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 18ee90a6c0..9ce3531d63 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 fread get a reading error occurred (not end-of-file), I don't think we need to run this part. > 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); > --
diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c index 18ee90a6c0..9ce3531d63 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); + else if (eof) + break; } - } + } while (!eof); /* flush the decoder */ decode(c, frame, NULL, outfilename);