[FFmpeg-cvslog] avcodec/nvenc: add support for unidirectional b-frames

Timo Rothenpieler git at videolan.org
Sun Mar 31 22:36:59 EEST 2024


ffmpeg | branch: master | Timo Rothenpieler <timo at rothenpieler.org> | Sun Mar 31 21:26:15 2024 +0200| [21b4708969415b9ec6d212fb35c12e4d1c28d066] | committer: Timo Rothenpieler

avcodec/nvenc: add support for unidirectional b-frames

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=21b4708969415b9ec6d212fb35c12e4d1c28d066
---

 libavcodec/nvenc.c      | 12 ++++++++++++
 libavcodec/nvenc.h      |  2 ++
 libavcodec/nvenc_hevc.c |  3 +++
 libavcodec/version.h    |  2 +-
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 7f938a519f..d121442957 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -613,6 +613,14 @@ static int nvenc_check_capabilities(AVCodecContext *avctx)
     }
 #endif
 
+#ifdef NVENC_HAVE_UNIDIR_B
+    ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_UNIDIRECTIONAL_B);
+    if(ctx->unidir_b && ret <= 0) {
+        av_log(avctx, AV_LOG_WARNING, "Unidirectional B-Frames not supported by the device\n");
+        return AVERROR(ENOSYS);
+    }
+#endif
+
     ctx->support_dyn_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
 
     return 0;
@@ -1658,6 +1666,10 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
     }
 
+#ifdef NVENC_HAVE_UNIDIR_B
+    ctx->init_encode_params.enableUniDirectionalB = ctx->unidir_b;
+#endif
+
     ctx->init_encode_params.enableEncodeAsync = 0;
     ctx->init_encode_params.enablePTD = 1;
 
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 3e207b1877..45860de722 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -89,6 +89,7 @@ typedef void ID3D11Device;
 #define NVENC_HAVE_TEMPORAL_FILTER
 #define NVENC_HAVE_LOOKAHEAD_LEVEL
 #define NVENC_HAVE_UHQ_TUNING
+#define NVENC_HAVE_UNIDIR_B
 #endif
 
 typedef struct NvencSurface
@@ -276,6 +277,7 @@ typedef struct NvencContext
     int rgb_mode;
     int tf_level;
     int lookahead_level;
+    int unidir_b;
 } NvencContext;
 
 int ff_nvenc_encode_init(AVCodecContext *avctx);
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index e0d16e82c7..bd8b6153f3 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -213,6 +213,9 @@ static const AVOption options[] = {
     { "1",            "",                                   0,                    AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LOOKAHEAD_LEVEL_1 }, 0, 0, VE, .unit = "lookahead_level" },
     { "2",            "",                                   0,                    AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LOOKAHEAD_LEVEL_2 }, 0, 0, VE, .unit = "lookahead_level" },
     { "3",            "",                                   0,                    AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LOOKAHEAD_LEVEL_3 }, 0, 0, VE, .unit = "lookahead_level" },
+#endif
+#ifdef NVENC_HAVE_UNIDIR_B
+    { "unidir_b",     "Enable use of unidirectional B-Frames.", OFFSET(unidir_b), AV_OPT_TYPE_BOOL,  { .i64 = 0 }, 0, 1, VE },
 #endif
     { NULL }
 };
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 06631ffa8c..7aa95fc3f1 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR   4
+#define LIBAVCODEC_VERSION_MINOR   5
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list