[FFmpeg-devel] [PATCH 2/2] lavc/encode: fix frame_number double-counted
Zhong Li
zhong.li at intel.com
Thu Jul 26 10:51:07 EEST 2018
Encoder frame_number may be double-counted if some frames are cached and then flushed.
Take qsv encoder (some frames are cached firsty for asynchronism) as example,
./ffmpeg -loglevel verbose -hwaccel qsv -c:v h264_qsv -i in.mp4 -vframes 100 -c:v h264_qsv out.mp4
frame_number passed to encoder is double-counted and larger than the accurate value.
Libx264 encoding with B frames can also reproduce it.
Signed-off-by: Zhong Li <zhong.li at intel.com>
---
libavcodec/encode.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index d976151..98c44c3 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -235,8 +235,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
if (ret >= 0)
avpkt->data = avpkt->buf->data;
}
-
- avctx->frame_number++;
+ if (frame)
+ avctx->frame_number++;
}
if (ret < 0 || !*got_packet_ptr) {
@@ -333,7 +333,8 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
avpkt->data = avpkt->buf->data;
}
- avctx->frame_number++;
+ if (frame)
+ avctx->frame_number++;
}
if (ret < 0 || !*got_packet_ptr)
--
2.7.4
More information about the ffmpeg-devel
mailing list