[FFmpeg-cvslog] avcodec/nvenc: add chroma qp offset support

Ricardo Monteiro git at videolan.org
Sun Aug 8 03:32:12 EEST 2021


ffmpeg | branch: master | Ricardo Monteiro <rmonteiro at nvidia.com> | Tue Aug  3 17:02:26 2021 +0200| [e56f6e59b6cbb2ebfa49bee8a21e6f4f09e7ade0] | committer: Timo Rothenpieler

avcodec/nvenc: add chroma qp offset support

Signed-off-by: Timo Rothenpieler <timo at rothenpieler.org>

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

 libavcodec/nvenc.c      | 9 +++++++++
 libavcodec/nvenc.h      | 7 +++++++
 libavcodec/nvenc_h264.c | 4 ++++
 libavcodec/nvenc_hevc.c | 4 ++++
 libavcodec/version.h    | 2 +-
 5 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index b52b6bda6d..32bcd4b318 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -743,6 +743,15 @@ static av_cold void set_constqp(AVCodecContext *avctx)
             rc->constQP.qpIntra = av_clip(ctx->cqp * fabs(avctx->i_quant_factor) + avctx->i_quant_offset + 0.5, 0, 51);
     }
 
+#ifdef NVENC_HAVE_QP_CHROMA_OFFSETS
+    rc->cbQPIndexOffset = ctx->qp_cb_offset;
+    rc->crQPIndexOffset = ctx->qp_cr_offset;
+#else
+    if (ctx->qp_cb_offset || ctx->qp_cr_offset) {
+        av_log(avctx, AV_LOG_WARNING, "Failed setting QP CB/CR offsets, SDK 11.1 or greater required at compile time.\n");
+    }
+#endif
+
     avctx->qmin = -1;
     avctx->qmax = -1;
 }
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 85d3a33601..7c284fbbd8 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -70,6 +70,11 @@ typedef void ID3D11Device;
 #define NVENC_HAVE_H264_LVL6
 #endif
 
+// SDK 11.1 compile time feature checks
+#if NVENCAPI_CHECK_VERSION(11, 1)
+#define NVENC_HAVE_QP_CHROMA_OFFSETS
+#endif
+
 typedef struct NvencSurface
 {
     NV_ENC_INPUT_PTR input_surface;
@@ -213,6 +218,8 @@ typedef struct NvencContext
     int init_qp_b;
     int init_qp_i;
     int cqp;
+    int qp_cb_offset;
+    int qp_cr_offset;
     int weighted_pred;
     int coder;
     int b_ref_mode;
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index c7af7fa682..fffdedcf6e 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -147,6 +147,10 @@ static const AVOption options[] = {
     { "init_qpI",     "Initial QP value for I frame",       OFFSET(init_qp_i),    AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, 51, VE },
     { "qp",           "Constant quantization parameter rate control method",
                                                             OFFSET(cqp),          AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, 51, VE },
+    { "qp_cb_offset", "Quantization parameter offset for cb channel",
+                                                            OFFSET(qp_cb_offset), AV_OPT_TYPE_INT,   { .i64 = 0 }, -12, 12, VE },
+    { "qp_cr_offset", "Quantization parameter offset for cr channel",
+                                                            OFFSET(qp_cr_offset), AV_OPT_TYPE_INT,   { .i64 = 0 }, -12, 12, VE },
     { "weighted_pred","Set 1 to enable weighted prediction",
                                                             OFFSET(weighted_pred),AV_OPT_TYPE_INT,   { .i64 = 0 }, 0, 1, VE },
     { "coder",        "Coder type",                         OFFSET(coder),        AV_OPT_TYPE_INT,   { .i64 = -1                                         },-1, 2, VE, "coder" },
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index c85a317518..4edc1797a0 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -134,6 +134,10 @@ static const AVOption options[] = {
     { "init_qpI",     "Initial QP value for I frame",       OFFSET(init_qp_i),    AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, 51, VE },
     { "qp",           "Constant quantization parameter rate control method",
                                                             OFFSET(cqp),          AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, 51, VE },
+    { "qp_cb_offset", "Quantization parameter offset for cb channel",
+                                                            OFFSET(qp_cb_offset), AV_OPT_TYPE_INT,   { .i64 = 0 }, -12, 12, VE },
+    { "qp_cr_offset", "Quantization parameter offset for cr channel",
+                                                            OFFSET(qp_cr_offset), AV_OPT_TYPE_INT,   { .i64 = 0 }, -12, 12, VE },
     { "weighted_pred","Set 1 to enable weighted prediction",
                                                             OFFSET(weighted_pred),AV_OPT_TYPE_INT,   { .i64 = 0 }, 0, 1, VE },
 #ifdef NVENC_HAVE_HEVC_BFRAME_REF_MODE
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 554f293aad..c2482428ca 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  59
 #define LIBAVCODEC_VERSION_MINOR   4
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list