[FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality and clamp initial qp value to [1, 51]
Agatha Hu
ahu at nvidia.com
Fri Dec 11 03:59:57 CET 2015
---
libavcodec/nvenc.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 43b8e78..6365434 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -762,6 +762,17 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
}
}
+ switch (avctx->codec->id) {
+ case AV_CODEC_ID_H264:
+ ctx->encode_config.encodeCodecConfig.h264Config.sliceMode = 3;
+ ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData = 1;
+ break;
+ case AV_CODEC_ID_H265:
+ ctx->encode_config.encodeCodecConfig.hevcConfig.sliceMode = 3;
+ ctx->encode_config.encodeCodecConfig.hevcConfig.sliceModeData = 1;
+ break;
+ }
+
/* when there're b frames, set dts offset */
if (ctx->encode_config.frameIntervalP >= 2)
ctx->last_dts = -2;
@@ -843,10 +854,10 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
ctx->encode_config.rcParams.initialRCQP.qpInterP = qp_inter_p;
if(avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) {
- ctx->encode_config.rcParams.initialRCQP.qpIntra = qp_inter_p * fabs(avctx->i_quant_factor);
- ctx->encode_config.rcParams.initialRCQP.qpIntra += avctx->i_quant_offset;
- ctx->encode_config.rcParams.initialRCQP.qpInterB = qp_inter_p * fabs(avctx->b_quant_factor);
- ctx->encode_config.rcParams.initialRCQP.qpInterB += avctx->b_quant_offset;
+ ctx->encode_config.rcParams.initialRCQP.qpIntra = av_clip(
+ qp_inter_p * fabs(avctx->i_quant_factor) + avctx->i_quant_offset, 0, 51);
+ ctx->encode_config.rcParams.initialRCQP.qpInterB = av_clip(
+ qp_inter_p * fabs(avctx->b_quant_factor) + avctx->b_quant_offset, 0, 51);
} else {
ctx->encode_config.rcParams.initialRCQP.qpIntra = qp_inter_p;
ctx->encode_config.rcParams.initialRCQP.qpInterB = qp_inter_p;
--
1.9.5.github.0
More information about the ffmpeg-devel
mailing list