summaryrefslogtreecommitdiff
path: root/doc/examples
diff options
context:
space:
mode:
authorZhao Zhili <quinkblack@foxmail.com>2021-07-14 10:58:42 +0800
committerZhao Zhili <zhilizhao@tencent.com>2022-04-22 11:26:51 +0800
commitd1a44f261aad2da5d2d4172b3782ee1b6402c3dc (patch)
tree2e40d6be02f2d5e1bbd04b7f109012356670eb85 /doc/examples
parent0b6e801d4ae176fc5fff5173f226ee7b400de3fe (diff)
examples/decode_video: flush parser to fix missing frame
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/decode_video.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c
index 18ee90a6c0..7238e38103 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,16 @@ 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)
+ if (ferror(f))
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 +172,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);