diff mbox

[FFmpeg-devel,2/2] lavc/encode: fix frame_number double-counted

Message ID 1532591467-13851-2-git-send-email-zhong.li@intel.com
State Accepted
Commit d91370e0f12a3fedd477616011566d9f2fb5e3e5
Headers show

Commit Message

Zhong Li July 26, 2018, 7:51 a.m. UTC
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@intel.com>
---
 libavcodec/encode.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Michael Niedermayer July 27, 2018, 7:27 p.m. UTC | #1
On Thu, Jul 26, 2018 at 03:51:07PM +0800, Zhong Li wrote:
> 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@intel.com>
> ---
>  libavcodec/encode.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

probably ok

[...]
Zhong Li Aug. 7, 2018, 2:46 a.m. UTC | #2
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf
> Of Michael Niedermayer
> Sent: Saturday, July 28, 2018 3:28 AM
> To: FFmpeg development discussions and patches
> <ffmpeg-devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/2] lavc/encode: fix frame_number
> double-counted
> 
> On Thu, Jul 26, 2018 at 03:51:07PM +0800, Zhong Li wrote:
> > 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@intel.com>
> > ---
> >  libavcodec/encode.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> probably ok

Thanks for review. Will push it if without any other comments.


> [...]
> --
> Michael     GnuPG fingerprint:
> 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Into a blind darkness they enter who follow after the Ignorance, they as if
> into a greater darkness enter who devote themselves to the Knowledge
> alone. -- Isha Upanishad
diff mbox

Patch

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)