diff mbox series

[FFmpeg-devel] nvenc: Fix output dts if encoding with implicitly enabled b-frames

Message ID 20210309123154.59060-1-martin@martin.st
State New
Headers show
Series [FFmpeg-devel] nvenc: Fix output dts if encoding with implicitly enabled b-frames
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Martin Storsjö March 9, 2021, 12:31 p.m. UTC
Since a0949d0bcb0eee2f3fffcf9a4810c0295d14c0dc, the b-frames
setting defaults to -1, which uses the preset's default setting.

If b-frames are enabled, but max_b_frames is kept at <= 0, the
output dts are inconsistent.
---
 libavcodec/nvenc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Martin Storsjö March 9, 2021, 2:30 p.m. UTC | #1
On Tue, 9 Mar 2021, Martin Storsjö wrote:

> Since a0949d0bcb0eee2f3fffcf9a4810c0295d14c0dc, the b-frames
> setting defaults to -1, which uses the preset's default setting.
>
> If b-frames are enabled, but max_b_frames is kept at <= 0, the
> output dts are inconsistent.
> ---
> libavcodec/nvenc.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> index a061dee880..6baeec6d36 100644
> --- a/libavcodec/nvenc.c
> +++ b/libavcodec/nvenc.c
> @@ -1380,8 +1380,11 @@ static av_cold int nvenc_setup_encoder(AVCodecContext *avctx)
>     if (res < 0)
>         return res;
>
> -    if (ctx->encode_config.frameIntervalP > 1)
> +    if (ctx->encode_config.frameIntervalP > 1) {
>         avctx->has_b_frames = 2;
> +        if (avctx->max_b_frames <= 0)
> +            avctx->max_b_frames = 1;
> +    }

Or maybe we just should change nvenc_set_timestamp to use has_b_frames 
instead if max_b_frames, iirc that's what's used to signal the number of 
frames to offset dts elsewhere?

Also, as long as the encoder doesn't use something like b-pyramid, 
shifting dts by 1 should be enough, regardless of the number of b-frames 
between p-frames.

// Martin
diff mbox series

Patch

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index a061dee880..6baeec6d36 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1380,8 +1380,11 @@  static av_cold int nvenc_setup_encoder(AVCodecContext *avctx)
     if (res < 0)
         return res;
 
-    if (ctx->encode_config.frameIntervalP > 1)
+    if (ctx->encode_config.frameIntervalP > 1) {
         avctx->has_b_frames = 2;
+        if (avctx->max_b_frames <= 0)
+            avctx->max_b_frames = 1;
+    }
 
     if (ctx->encode_config.rcParams.averageBitRate > 0)
         avctx->bit_rate = ctx->encode_config.rcParams.averageBitRate;