mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-02-08 15:50:18 +00:00
examples/decode_video: flush parser to fix missing frame
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
This commit is contained in:
parent
0b6e801d4a
commit
d1a44f261a
@ -92,6 +92,7 @@ int main(int argc, char **argv)
|
|||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
size_t data_size;
|
size_t data_size;
|
||||||
int ret;
|
int ret;
|
||||||
|
int eof;
|
||||||
AVPacket *pkt;
|
AVPacket *pkt;
|
||||||
|
|
||||||
if (argc <= 2) {
|
if (argc <= 2) {
|
||||||
@ -150,15 +151,16 @@ int main(int argc, char **argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!feof(f)) {
|
do {
|
||||||
/* read raw data from the input file */
|
/* read raw data from the input file */
|
||||||
data_size = fread(inbuf, 1, INBUF_SIZE, f);
|
data_size = fread(inbuf, 1, INBUF_SIZE, f);
|
||||||
if (!data_size)
|
if (ferror(f))
|
||||||
break;
|
break;
|
||||||
|
eof = !data_size;
|
||||||
|
|
||||||
/* use the parser to split the data into frames */
|
/* use the parser to split the data into frames */
|
||||||
data = inbuf;
|
data = inbuf;
|
||||||
while (data_size > 0) {
|
while (data_size > 0 || eof) {
|
||||||
ret = av_parser_parse2(parser, c, &pkt->data, &pkt->size,
|
ret = av_parser_parse2(parser, c, &pkt->data, &pkt->size,
|
||||||
data, data_size, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);
|
data, data_size, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -170,8 +172,10 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (pkt->size)
|
if (pkt->size)
|
||||||
decode(c, frame, pkt, outfilename);
|
decode(c, frame, pkt, outfilename);
|
||||||
|
else if (eof)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while (!eof);
|
||||||
|
|
||||||
/* flush the decoder */
|
/* flush the decoder */
|
||||||
decode(c, frame, NULL, outfilename);
|
decode(c, frame, NULL, outfilename);
|
||||||
|
Loading…
Reference in New Issue
Block a user