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

Martin Storsjö martin at martin.st
Tue Mar 9 14:31:54 EET 2021


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;
+    }
 
     if (ctx->encode_config.rcParams.averageBitRate > 0)
         avctx->bit_rate = ctx->encode_config.rcParams.averageBitRate;
-- 
2.24.3 (Apple Git-128)



More information about the ffmpeg-devel mailing list