Signed-off-by: Diego Biurrun <diego@biurrun.de>tags/n4.0
| @@ -519,6 +519,8 @@ static void set_constqp(AVCodecContext *avctx, NV_ENC_RC_PARAMS *rc) | |||||
| static void set_vbr(AVCodecContext *avctx, NV_ENC_RC_PARAMS *rc) | static void set_vbr(AVCodecContext *avctx, NV_ENC_RC_PARAMS *rc) | ||||
| { | { | ||||
| NVENCContext *ctx = avctx->priv_data; | |||||
| if (avctx->qmin >= 0) { | if (avctx->qmin >= 0) { | ||||
| rc->enableMinQP = 1; | rc->enableMinQP = 1; | ||||
| rc->minQP.qpInterB = avctx->qmin; | rc->minQP.qpInterB = avctx->qmin; | ||||
| @@ -532,6 +534,30 @@ static void set_vbr(AVCodecContext *avctx, NV_ENC_RC_PARAMS *rc) | |||||
| rc->maxQP.qpInterP = avctx->qmax; | rc->maxQP.qpInterP = avctx->qmax; | ||||
| rc->maxQP.qpIntra = avctx->qmax; | rc->maxQP.qpIntra = avctx->qmax; | ||||
| } | } | ||||
| if (ctx->init_qp_p >= 0) { | |||||
| rc->enableInitialRCQP = 1; | |||||
| rc->initialRCQP.qpInterP = ctx->init_qp_p; | |||||
| if (ctx->init_qp_i < 0) { | |||||
| if (avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) { | |||||
| rc->initialRCQP.qpIntra = av_clip(rc->initialRCQP.qpInterP * fabs(avctx->i_quant_factor) + avctx->i_quant_offset + 0.5, 0, 51); | |||||
| } else { | |||||
| rc->initialRCQP.qpIntra = rc->initialRCQP.qpInterP; | |||||
| } | |||||
| } else { | |||||
| rc->initialRCQP.qpIntra = ctx->init_qp_i; | |||||
| } | |||||
| if (ctx->init_qp_b < 0) { | |||||
| if (avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) { | |||||
| rc->initialRCQP.qpInterB = av_clip(rc->initialRCQP.qpInterP * fabs(avctx->b_quant_factor) + avctx->b_quant_offset + 0.5, 0, 51); | |||||
| } else { | |||||
| rc->initialRCQP.qpInterB = rc->initialRCQP.qpInterP; | |||||
| } | |||||
| } else { | |||||
| rc->initialRCQP.qpInterB = ctx->init_qp_b; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| static void set_lossless(AVCodecContext *avctx, NV_ENC_RC_PARAMS *rc) | static void set_lossless(AVCodecContext *avctx, NV_ENC_RC_PARAMS *rc) | ||||
| @@ -183,6 +183,9 @@ typedef struct NVENCContext { | |||||
| int strict_gop; | int strict_gop; | ||||
| int aq_strength; | int aq_strength; | ||||
| int quality; | int quality; | ||||
| int init_qp_p; | |||||
| int init_qp_b; | |||||
| int init_qp_i; | |||||
| } NVENCContext; | } NVENCContext; | ||||
| int ff_nvenc_encode_init(AVCodecContext *avctx); | int ff_nvenc_encode_init(AVCodecContext *avctx); | ||||
| @@ -89,6 +89,9 @@ static const AVOption options[] = { | |||||
| { "aq-strength", "When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive)", OFFSET(aq_strength), AV_OPT_TYPE_INT, { .i64 = 8 }, 1, 15, VE }, | { "aq-strength", "When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive)", OFFSET(aq_strength), AV_OPT_TYPE_INT, { .i64 = 8 }, 1, 15, VE }, | ||||
| { "cq", "Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control", OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 51, VE }, | { "cq", "Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control", OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 51, VE }, | ||||
| #endif /* NVENCAPI_MAJOR_VERSION >= 7 */ | #endif /* NVENCAPI_MAJOR_VERSION >= 7 */ | ||||
| { "init_qpP", "Initial QP value for P-frames", OFFSET(init_qp_p), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51, VE }, | |||||
| { "init_qpB", "Initial QP value for B-frames", OFFSET(init_qp_b), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51, VE }, | |||||
| { "init_qpI", "Initial QP value for I-frames", OFFSET(init_qp_i), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51, VE }, | |||||
| { NULL } | { NULL } | ||||
| }; | }; | ||||
| @@ -87,6 +87,9 @@ static const AVOption options[] = { | |||||
| { "aq-strength", "When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive)", OFFSET(aq_strength), AV_OPT_TYPE_INT, { .i64 = 8 }, 1, 15, VE }, | { "aq-strength", "When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive)", OFFSET(aq_strength), AV_OPT_TYPE_INT, { .i64 = 8 }, 1, 15, VE }, | ||||
| { "cq", "Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control", OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 51, VE }, | { "cq", "Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control", OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 51, VE }, | ||||
| #endif /* NVENCAPI_MAJOR_VERSION >= 7 */ | #endif /* NVENCAPI_MAJOR_VERSION >= 7 */ | ||||
| { "init_qpP", "Initial QP value for P-frames", OFFSET(init_qp_p), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51, VE }, | |||||
| { "init_qpB", "Initial QP value for B-frames", OFFSET(init_qp_b), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51, VE }, | |||||
| { "init_qpI", "Initial QP value for I-frames", OFFSET(init_qp_i), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51, VE }, | |||||
| { NULL } | { NULL } | ||||
| }; | }; | ||||