[FFmpeg-cvslog] avcodec/nvenc: allow different const-qps for I, P and B frames

Konda Raju git at videolan.org
Fri Mar 17 12:52:17 EET 2017


ffmpeg | branch: master | Konda Raju <kraju at nvidia.com> | Fri Mar 17 10:00:25 2017 +0530| [2db5ab73d43a8c22616e686ab12f94223910c761] | committer: Timo Rothenpieler

avcodec/nvenc: allow different const-qps for I, P and B frames

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

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

 libavcodec/nvenc.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index d9fef52..dd9ebc1 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -507,9 +507,26 @@ static av_cold void set_constqp(AVCodecContext *avctx)
     NV_ENC_RC_PARAMS *rc = &ctx->encode_config.rcParams;
 
     rc->rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
-    rc->constQP.qpInterB = avctx->global_quality;
-    rc->constQP.qpInterP = avctx->global_quality;
-    rc->constQP.qpIntra = avctx->global_quality;
+
+    if (ctx->init_qp_p >= 0) {
+        rc->constQP.qpInterP = ctx->init_qp_p;
+        if (ctx->init_qp_i >= 0 && ctx->init_qp_b >= 0) {
+            rc->constQP.qpIntra = ctx->init_qp_i;
+            rc->constQP.qpInterB = ctx->init_qp_b;
+        } else if (avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) {
+            rc->constQP.qpIntra = av_clip(
+                rc->constQP.qpInterP * fabs(avctx->i_quant_factor) + avctx->i_quant_offset + 0.5, 0, 51);
+            rc->constQP.qpInterB = av_clip(
+                rc->constQP.qpInterP * fabs(avctx->b_quant_factor) + avctx->b_quant_offset + 0.5, 0, 51);
+        } else {
+            rc->constQP.qpIntra = rc->constQP.qpInterP;
+            rc->constQP.qpInterB = rc->constQP.qpInterP;
+        }
+    } else if (avctx->global_quality > 0) {
+        rc->constQP.qpInterP = avctx->global_quality;
+        rc->constQP.qpInterB = avctx->global_quality;
+        rc->constQP.qpIntra = avctx->global_quality;
+    }
 
     avctx->qmin = -1;
     avctx->qmax = -1;
@@ -598,12 +615,6 @@ static void nvenc_override_rate_control(AVCodecContext *avctx)
 
     switch (ctx->rc) {
     case NV_ENC_PARAMS_RC_CONSTQP:
-        if (avctx->global_quality <= 0) {
-            av_log(avctx, AV_LOG_WARNING,
-                   "The constant quality rate-control requires "
-                   "the 'global_quality' option set.\n");
-            return;
-        }
         set_constqp(avctx);
         return;
     case NV_ENC_PARAMS_RC_VBR_MINQP:



More information about the ffmpeg-cvslog mailing list