[FFmpeg-devel] unsubscribe
--- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. --- ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] Fix H264 and HEVC vui info update
--- libavcodec/nvenc.c | 33 - 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index a3b02fa..5694f17 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -867,15 +867,22 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } switch (avctx->codec->id) { -case AV_CODEC_ID_H264: - ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = 1; - ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = 1; - +case AV_CODEC_ID_H264: ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourMatrix = avctx->colorspace; ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourPrimaries = avctx->color_primaries; ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.transferCharacteristics = avctx->color_trc; + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag = +(avctx->color_range == AVCOL_RANGE_JPEG || avctx->pix_fmt == AV_PIX_FMT_YUVJ420P || +avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P); + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFormat = 5; // 5=unspecified - ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag = avctx->color_range == AVCOL_RANGE_JPEG; + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = + (avctx->colorspace != 2 || avctx->color_primaries != 2 || avctx->color_trc != 2); + + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = + (ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag + || ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFormat != 5 + || ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag != 0); ctx->encode_config.encodeCodecConfig.h264Config.sliceMode = 3; ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData = 1; @@ -944,6 +951,22 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) break; case AV_CODEC_ID_H265: + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourMatrix = avctx->colorspace; + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourPrimaries = avctx->color_primaries; + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.transferCharacteristics = avctx->color_trc; + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFullRangeFlag = +(avctx->color_range == AVCOL_RANGE_JPEG || avctx->pix_fmt == AV_PIX_FMT_YUVJ420P || +avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P); + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFormat = 5; // 5=unspecified + + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourDescriptionPresentFlag = + (avctx->colorspace != 2 || avctx->color_primaries != 2 || avctx->color_trc != 2); + + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoSignalTypePresentFlag = + (ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourDescriptionPresentFlag + || ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFormat != 5 + || ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFullRangeFlag != 0); + ctx->encode_config.encodeCodecConfig.hevcConfig.sliceMode = 3; ctx->encode_config.encodeCodecConfig.hevcConfig.sliceModeData = 1; -- 1.9.1 --- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. --- ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] nvenc.c Fix H264 and HEVC vui info update
Yes. That's stange, let me try again On 2016/3/4 14:50, Timothy Gu wrote: On Fri, Mar 04, 2016 at 12:45:47PM +0800, Agatha Hu wrote: --- libavcodec/nvenc.c | 33 - 1 file changed, 28 insertions(+), 5 deletions(-) This patched is corrupted by your mail client. What's wrong with the first patch you sent (with git-send-email)? Timothy ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] nvenc.c Fix H264 and HEVC vui info update
--- libavcodec/nvenc.c | 33 - 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index a3b02fa..5694f17 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -867,15 +867,22 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } switch (avctx->codec->id) { -case AV_CODEC_ID_H264: - ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = 1; - ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = 1; - +case AV_CODEC_ID_H264: ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourMatrix = avctx->colorspace; ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourPrimaries = avctx->color_primaries; ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.transferCharacteristics = avctx->color_trc; + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag = +(avctx->color_range == AVCOL_RANGE_JPEG || avctx->pix_fmt == AV_PIX_FMT_YUVJ420P || +avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P); + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFormat = 5; // 5=unspecified - ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag = avctx->color_range == AVCOL_RANGE_JPEG; + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = + (avctx->colorspace != 2 || avctx->color_primaries != 2 || avctx->color_trc != 2); + + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = + (ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag + || ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFormat != 5 + || ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag != 0); ctx->encode_config.encodeCodecConfig.h264Config.sliceMode = 3; ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData = 1; @@ -944,6 +951,22 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) break; case AV_CODEC_ID_H265: + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourMatrix = avctx->colorspace; + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourPrimaries = avctx->color_primaries; + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.transferCharacteristics = avctx->color_trc; + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFullRangeFlag = +(avctx->color_range == AVCOL_RANGE_JPEG || avctx->pix_fmt == AV_PIX_FMT_YUVJ420P || +avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P); + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFormat = 5; // 5=unspecified + + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourDescriptionPresentFlag = + (avctx->colorspace != 2 || avctx->color_primaries != 2 || avctx->color_trc != 2); + + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoSignalTypePresentFlag = + (ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourDescriptionPresentFlag + || ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFormat != 5 + || ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFullRangeFlag != 0); + ctx->encode_config.encodeCodecConfig.hevcConfig.sliceMode = 3; ctx->encode_config.encodeCodecConfig.hevcConfig.sliceModeData = 1; -- 1.9.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] Fix H264 and HEVC vui info update
--- libavcodec/nvenc.c | 33 - 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index a3b02fa..5694f17 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -867,15 +867,22 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } switch (avctx->codec->id) { -case AV_CODEC_ID_H264: - ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = 1; - ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = 1; - +case AV_CODEC_ID_H264: ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourMatrix = avctx->colorspace; ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourPrimaries = avctx->color_primaries; ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.transferCharacteristics = avctx->color_trc; + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag = +(avctx->color_range == AVCOL_RANGE_JPEG || avctx->pix_fmt == AV_PIX_FMT_YUVJ420P || +avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P); + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFormat = 5; // 5=unspecified - ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag = avctx->color_range == AVCOL_RANGE_JPEG; + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = + (avctx->colorspace != 2 || avctx->color_primaries != 2 || avctx->color_trc != 2); + + ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = + (ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag + || ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFormat != 5 + || ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag != 0); ctx->encode_config.encodeCodecConfig.h264Config.sliceMode = 3; ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData = 1; @@ -944,6 +951,22 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) break; case AV_CODEC_ID_H265: + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourMatrix = avctx->colorspace; + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourPrimaries = avctx->color_primaries; + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.transferCharacteristics = avctx->color_trc; + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFullRangeFlag = +(avctx->color_range == AVCOL_RANGE_JPEG || avctx->pix_fmt == AV_PIX_FMT_YUVJ420P || +avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || avctx->pix_fmt == AV_PIX_FMT_YUVJ444P); + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFormat = 5; // 5=unspecified + + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourDescriptionPresentFlag = + (avctx->colorspace != 2 || avctx->color_primaries != 2 || avctx->color_trc != 2); + + ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoSignalTypePresentFlag = + (ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.colourDescriptionPresentFlag + || ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFormat != 5 + || ctx->encode_config.encodeCodecConfig.hevcConfig.hevcVUIParameters.videoFullRangeFlag != 0); + ctx->encode_config.encodeCodecConfig.hevcConfig.sliceMode = 3; ctx->encode_config.encodeCodecConfig.hevcConfig.sliceModeData = 1; -- 1.9.1 --- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. --- ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality and clamp initial qp value to [1, 51]
On 2015/12/11 17:20, Timo Rothenpieler wrote: * PGP Signed by an unknown key Hi all, before switching to the new released nvenc6.0 header, can you take a look at this fix? I'm fine with making it the default, the only concern i have is weather it has any side-effects, like reduced performance that impacts some higher resolutions which can't be encoded in realtime anymore. If that's not the case, this LGTM. No, it won't affect performance, we did lots of internal tests, mainly focused on quality improvement. But if it makes performance worse we won't apply it anyway. Agatha Hu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality and clamp initial qp value to [1, 51]
--- 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality and clamp initial qp value to [1, 51]
--- 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 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality and clamp initial qp value to [1, 51]
On 2015/12/11 11:10, Agatha Hu wrote: --- 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; Hi all, before switching to the new released nvenc6.0 header, can you take a look at this fix? Agatha Hu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality
--- libavcodec/nvenc.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 43b8e78..f0e5a19 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; -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality
在 2015/12/5 3:26, Timo Rothenpieler 写道: --- libavcodec/nvenc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 43b8e78..b8f7f91 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -762,6 +762,9 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } } +ctx->encode_config.encodeCodecConfig.h264Config.sliceMode = 3; + ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData = 1; It's missing a check if we are encoding h264 or hevc. Does it have any negative sideeffects, or does it just increase the image quality? /* when there're b frames, set dts offset */ if (ctx->encode_config.frameIntervalP >= 2) ctx->last_dts = -2; ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel Yes, need add a check Just aimed to increase image quality. Nvidia are doing some interal tests to tune the quality --- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. --- ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality
在 2015/12/5 3:26, Timo Rothenpieler 写道: --- libavcodec/nvenc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 43b8e78..b8f7f91 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -762,6 +762,9 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } } +ctx->encode_config.encodeCodecConfig.h264Config.sliceMode = 3; + ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData = 1; It's missing a check if we are encoding h264 or hevc. Does it have any negative sideeffects, or does it just increase the image quality? /* when there're b frames, set dts offset */ if (ctx->encode_config.frameIntervalP >= 2) ctx->last_dts = -2; ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel Yes, need add a check Just aimed to increase image quality. Nvidia are doing some interal tests to tune the quality Agatha Hu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality
--- libavcodec/nvenc.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 43b8e78..f0e5a19 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; -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality
--- libavcodec/nvenc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 43b8e78..b8f7f91 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -762,6 +762,9 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } } +ctx->encode_config.encodeCodecConfig.h264Config.sliceMode = 3; +ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData = 1; + /* when there're b frames, set dts offset */ if (ctx->encode_config.frameIntervalP >= 2) ctx->last_dts = -2; -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] nvenc set slice number to 1 to improve encoding quality
--- libavcodec/nvenc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 43b8e78..b8f7f91 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -762,6 +762,9 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } } +ctx->encode_config.encodeCodecConfig.h264Config.sliceMode = 3; +ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData = 1; + /* when there're b frames, set dts offset */ if (ctx->encode_config.frameIntervalP >= 2) ctx->last_dts = -2; -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] have some major changes for nvenc support
Hi, Recently Nvidia did some work on improving nvenc performance, it includes lots of change so I attach the patch instead of direct send. Here are the explanations: 1) The first main change is adding an nvresize filter (1:N, one input, multiple outputs) to do hardware resizing, because during our interal 1:N encoding test, we found swscale becomes bottleneck. So we use cuda kernel instead. 2) We use AVFrame::opaque field to store a customized ffnvinfo struture to prevent expensive CPU<->GPU transferration. Without it, the workflow will be like CPU AVFrame input-->copy to GPU-->do CUDA resizing-->copy to CPU AVFrame-->copy to GPU-->NVENC encoding. And now it becomes: CPU AVFrame input-->copy to GPU-->do CUDA resizing-->NVENC encoding. Our strategy is to check whether AVFrame::opaque is not null AND its first 128 bytes matches some particular GUID. If so, AVFrame::opaque is a valid ffnvinfo struture and we read GPU address directly from it instead of copying data from AVFrame. Nvresize filter has a -readback parameter, if it's set as 0, resized result won't be copied back to CPU, mostly in case it's connected to an NVENC encoder。 If it's set as 1, resized result will still be copied back to AVFrame so that it could be compatible with other components. 3) Because we are using CUDA address now, input buffer becomes CUDA external memory. We replaced NvEncCreateInputBuffer to cuMemAllocPitch+NvEncRegisterInputBuffer, and NvEncLock/UnlockInputBuffer to NvEncMap/UnmapInputBuffer. 4) And because of using cuda input, it exposed some driver bugs, e.g. nvenc generates corrupted chroma plane data if buffer format is YUV420p. Bug-fixed driver will soon be released, but considering backwards compatibility we decided to convert YUV420P to NV12 explicitly by a cuda kernel in nvenc.c. Even in the bug-fixed driver, there's still a YUV420P->NV12 conversion kernel. The only difference is that kernel is provided along with driver, but here we did it within nvenc.c. The same reason, YUV444P is removed temporarily, there's a bug for cuda input. Once the fix is released, we should enable the support again. We choose to backwards support YUV420p is because it's much more popular than YUV444P. 5) Last is, we move most of cuda typedefs/functions/helpers to cudautils.h/c A typical use case is: ffmpeg -y -i $1 $2 $3 -filter_complex \ nvresize=5:s=hd1080\|hd720\|hd480\|wvga\|cif:readback=0[out0][out1][out2][out3][out4] \ -map [out0] -an -vcodec nvenc_h264 -preset slow -profile:v main -async 1 -b:v 200M -bufsize 200M -maxrate 200M -refs 1 -bf 2 $1_1080p.mp4 \ -map [out1] -an -vcodec nvenc_h264 -preset slow -profile:v main -async 1 -b:v 100M -bufsize 100M -maxrate 100M -refs 1 -bf 2 $1_720p.mp4 \ -map [out2] -an -vcodec nvenc_h264 -preset slow -profile:v main -async 1 -b:v 50M -bufsize 50M -maxrate 50M -refs 1 -bf 2 $1_480p.mp4 \ -map [out3] -an -vcodec nvenc_h264 -preset slow -profile:v main -async 1 -b:v 25M -bufsize 25M -maxrate 25M -refs 1 -bf 2 $1_wvga.mp4 \ -map [out4] -an -vcodec nvenc_h264 -preset slow -profile:v main -async 1 -b:v 10M -bufsize 10M -maxrate 10M -refs 1 -bf 2 $1_cif.mp4 Thanks Agatha Hu >From 4bb843a47cbcef9c0383efb7e573f0f8eadb65d6 Mon Sep 17 00:00:00 2001 From: Ganapathy Kasi <gk...@nvidia.com> Date: Wed, 4 Nov 2015 22:22:35 -0800 Subject: [PATCH] combined: cuda resize,yuv420 fix,remove yuv444,add AQ --- libavcodec/Makefile | 2 +- libavcodec/nvenc.c| 435 ++- libavcodec/nvenc_ptx.c| 240 +++ libavfilter/Makefile | 2 + libavfilter/allfilters.c | 1 + libavfilter/vf_nvresize.c | 669 ++ libavfilter/vf_nvresize_ptx.c | 659 + libavutil/Makefile| 2 + libavutil/cudautils.c | 288 ++ libavutil/cudautils.h | 216 ++ 10 files changed, 2241 insertions(+), 273 deletions(-) create mode 100644 libavcodec/nvenc_ptx.c create mode 100644 libavfilter/vf_nvresize.c create mode 100644 libavfilter/vf_nvresize_ptx.c create mode 100644 libavutil/cudautils.c create mode 100644 libavutil/cudautils.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 67fb72a..45ac476 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -98,7 +98,7 @@ OBJS-$(CONFIG_MPEGVIDEOENC)+= mpegvideo_enc.o mpeg12data.o \ motion_est.o ratecontrol.o\ mpegvideoencdsp.o OBJS-$(CONFIG_MSS34DSP)+= mss34dsp.o -OBJS-$(CONFIG_NVENC) += nvenc.o +OBJS-$(CONFIG_NVENC) += nvenc.o nvenc_ptx.o OBJS-$(CONFIG_PIXBLOCKDSP) += pixblockdsp.o OBJS-$(CONFIG_QPELDSP) += qpeldsp.o OBJS-$(CONFIG_QS
Re: [FFmpeg-devel] have some major changes for nvenc support
在 2015/11/5 18:31, wm4 写道: On Thu, 5 Nov 2015 16:23:04 +0800 Agatha Hu <a...@nvidia.com> wrote: 2) We use AVFrame::opaque field to store a customized ffnvinfo struture to prevent expensive CPU<->GPU transferration. Without it, the workflow will be like CPU AVFrame input-->copy to GPU-->do CUDA resizing-->copy to CPU AVFrame-->copy to GPU-->NVENC encoding. And now it becomes: CPU AVFrame input-->copy to GPU-->do CUDA resizing-->NVENC encoding. Our strategy is to check whether AVFrame::opaque is not null AND its first 128 bytes matches some particular GUID. If so, AVFrame::opaque is a valid ffnvinfo struture and we read GPU address directly from it instead of copying data from AVFrame. Please no, not another hack that makes the hw decoding API situation worse. Do this properly and coordinate with Gwenole Beauchesne, who plans improvements into this direction. Try to catch on with Gwenole Beauchesne's work, is the related AVHWAccelFrame available for use now? Agatha Hu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] fix nvenc potential profile error when encoding yuv444p
--- libavcodec/nvenc.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 0e6ef43..083e494 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -912,6 +912,11 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) goto error; } } +// force setting profile as high444p if input is AV_PIX_FMT_YUV444P +if (avctx->pix_fmt == AV_PIX_FMT_YUV444P) { +ctx->encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID; +avctx->profile = FF_PROFILE_H264_HIGH_444_PREDICTIVE; +} ctx->encode_config.encodeCodecConfig.h264Config.chromaFormatIDC = avctx->profile == FF_PROFILE_H264_HIGH_444_PREDICTIVE ? 3 : 1; @@ -1452,7 +1457,7 @@ static const enum AVPixelFormat pix_fmts_nvenc[] = { #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { { "preset", "Set the encoding preset (one of slow = hq 2pass, medium = hq, fast = hp, hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE }, -{ "profile", "Set the encoding profile (high, main or baseline)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, +{ "profile", "Set the encoding profile (high, main, baseline or high444p)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "level", "Set the encoding level restriction (auto, 1.0, 1.0b, 1.1, 1.2, ..., 4.2, 5.0, 5.1)", OFFSET(level), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "tier", "Set the encoding tier (main or high)", OFFSET(tier), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] fix nvenc potential profile error when encoding yuv444p
--- libavcodec/nvenc.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 0e6ef43..083e494 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -912,6 +912,11 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) goto error; } } +// force setting profile as high444p if input is AV_PIX_FMT_YUV444P +if (avctx->pix_fmt == AV_PIX_FMT_YUV444P) { +ctx->encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID; +avctx->profile = FF_PROFILE_H264_HIGH_444_PREDICTIVE; +} ctx->encode_config.encodeCodecConfig.h264Config.chromaFormatIDC = avctx->profile == FF_PROFILE_H264_HIGH_444_PREDICTIVE ? 3 : 1; @@ -1452,7 +1457,7 @@ static const enum AVPixelFormat pix_fmts_nvenc[] = { #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { { "preset", "Set the encoding preset (one of slow = hq 2pass, medium = hq, fast = hp, hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE }, -{ "profile", "Set the encoding profile (high, main or baseline)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, +{ "profile", "Set the encoding profile (high, main, baseline or high444p)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "level", "Set the encoding level restriction (auto, 1.0, 1.0b, 1.1, 1.2, ..., 4.2, 5.0, 5.1)", OFFSET(level), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "tier", "Set the encoding tier (main or high)", OFFSET(tier), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] fix nvenc potential profile error when encoding yuv444p
在 2015/10/28 14:53, Agatha Hu 写道: --- libavcodec/nvenc.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 0e6ef43..083e494 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -912,6 +912,11 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) goto error; } } +// force setting profile as high444p if input is AV_PIX_FMT_YUV444P +if (avctx->pix_fmt == AV_PIX_FMT_YUV444P) { +ctx->encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID; +avctx->profile = FF_PROFILE_H264_HIGH_444_PREDICTIVE; +} ctx->encode_config.encodeCodecConfig.h264Config.chromaFormatIDC = avctx->profile == FF_PROFILE_H264_HIGH_444_PREDICTIVE ? 3 : 1; @@ -1452,7 +1457,7 @@ static const enum AVPixelFormat pix_fmts_nvenc[] = { #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { { "preset", "Set the encoding preset (one of slow = hq 2pass, medium = hq, fast = hp, hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE }, -{ "profile", "Set the encoding profile (high, main or baseline)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, +{ "profile", "Set the encoding profile (high, main, baseline or high444p)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "level", "Set the encoding level restriction (auto, 1.0, 1.0b, 1.1, 1.2, ..., 4.2, 5.0, 5.1)", OFFSET(level), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "tier", "Set the encoding tier (main or high)", OFFSET(tier), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, The original nvenc.c misses "yuv444p" in option explanation, and since yuv444p is only for AV_PIX_FMT_YUV444P input, force setting the profile to prevent error. Agatha Hu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] fix b frame n_quant_offset
在 2015/10/9 17:38, Agatha Hu 写道: --- libavcodec/nvenc.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 18bcd96..0e6ef43 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -742,8 +742,6 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) switch (avctx->codec->id) { case AV_CODEC_ID_H264: ctx->encode_config.encodeCodecConfig.h264Config.idrPeriod = avctx->gop_size; - ctx->encode_config.encodeCodecConfig.h264Config.hierarchicalPFrames = 1; - ctx->encode_config.encodeCodecConfig.h264Config.hierarchicalBFrames = 1; break; case AV_CODEC_ID_H265: ctx->encode_config.encodeCodecConfig.hevcConfig.idrPeriod = avctx->gop_size; @@ -843,9 +841,9 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) 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 += qp_inter_p * avctx->i_quant_offset; +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 += qp_inter_p * avctx->b_quant_offset; +ctx->encode_config.rcParams.initialRCQP.qpInterB += avctx->b_quant_offset; } else { ctx->encode_config.rcParams.initialRCQP.qpIntra = qp_inter_p; ctx->encode_config.rcParams.initialRCQP.qpInterB = qp_inter_p; Anyone takes a look at this patch? Thanks ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] fix b frame n_quant_offset
--- libavcodec/nvenc.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 18bcd96..0e6ef43 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -742,8 +742,6 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) switch (avctx->codec->id) { case AV_CODEC_ID_H264: ctx->encode_config.encodeCodecConfig.h264Config.idrPeriod = avctx->gop_size; - ctx->encode_config.encodeCodecConfig.h264Config.hierarchicalPFrames = 1; - ctx->encode_config.encodeCodecConfig.h264Config.hierarchicalBFrames = 1; break; case AV_CODEC_ID_H265: ctx->encode_config.encodeCodecConfig.hevcConfig.idrPeriod = avctx->gop_size; @@ -843,9 +841,9 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) 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 += qp_inter_p * avctx->i_quant_offset; +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 += qp_inter_p * avctx->b_quant_offset; +ctx->encode_config.rcParams.initialRCQP.qpInterB += avctx->b_quant_offset; } else { ctx->encode_config.rcParams.initialRCQP.qpIntra = qp_inter_p; ctx->encode_config.rcParams.initialRCQP.qpInterB = qp_inter_p; -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] fix b frame n_quant_offset for nvenc
--- libavcodec/nvenc.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 18bcd96..0e6ef43 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -742,8 +742,6 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) switch (avctx->codec->id) { case AV_CODEC_ID_H264: ctx->encode_config.encodeCodecConfig.h264Config.idrPeriod = avctx->gop_size; - ctx->encode_config.encodeCodecConfig.h264Config.hierarchicalPFrames = 1; - ctx->encode_config.encodeCodecConfig.h264Config.hierarchicalBFrames = 1; break; case AV_CODEC_ID_H265: ctx->encode_config.encodeCodecConfig.hevcConfig.idrPeriod = avctx->gop_size; @@ -843,9 +841,9 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) 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 += qp_inter_p * avctx->i_quant_offset; +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 += qp_inter_p * avctx->b_quant_offset; +ctx->encode_config.rcParams.initialRCQP.qpInterB += avctx->b_quant_offset; } else { ctx->encode_config.rcParams.initialRCQP.qpIntra = qp_inter_p; ctx->encode_config.rcParams.initialRCQP.qpInterB = qp_inter_p; -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 2/3] Optimize nvenc parameters, add 3 more presets: fast, medium, slow
在 2015/9/12 11:18, Philip Langdale 写道: On Fri, 11 Sep 2015 17:32:06 +0800 Agatha Hu <a...@nvidia.com> wrote: From: ahu <ahu@ubuntu.(none)> --- libavcodec/nvenc.c | 59 +++- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 3174b01..fd90f7b 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -610,8 +610,17 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) if (ctx->preset) { if (!strcmp(ctx->preset, "hp")) { encoder_preset = NV_ENC_PRESET_HP_GUID; +} else if (!strcmp(ctx->preset, "fast")) { +ctx->twopass = 0; +encoder_preset = NV_ENC_PRESET_HQ_GUID; Should this be HP_GUID? Your updated help text below says fast == hp. Rest is fine. --phil Yes you're right, another typo. Fix by attached patch (Based on Timo's branch, others seem fine to me). Agatha Hu --- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. --- >From c8dc71d311989b536ba63c9a7381d0aefd6c7bf9 Mon Sep 17 00:00:00 2001 From: Agatha Hu <a...@nvidia.com> Date: Mon, 14 Sep 2015 11:15:19 +0800 Subject: [PATCH] avcode nvenc fix fast preset X-NVConfidentiality: public --- libavcodec/nvenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 4c387fe..18bcd96 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -616,7 +616,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) encoder_preset = NV_ENC_PRESET_HQ_GUID; ctx->twopass = 0; } else if (!strcmp(ctx->preset, "fast")) { -encoder_preset = NV_ENC_PRESET_HQ_GUID; +encoder_preset = NV_ENC_PRESET_HP_GUID; ctx->twopass = 0; } else if (!strcmp(ctx->preset, "hq")) { encoder_preset = NV_ENC_PRESET_HQ_GUID; -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] Optimize nvenc parameters, add 3 more presets: fast, medium, slow
在 2015/9/11 17:45, Timo Rothenpieler 写道: * PGP Signed by an unknown key I applied the patch to the current ffmpeg master and made some style adjustments, you can take a look on my github fork: https://github.com/BtbN/FFmpeg/commit/3b5964c521343b883f92079765148fd630a9370c I also attached the patch for reference. Any comments? * Unknown Key * 0xA6DA5D0F I just sent 3 patches following your suggestion (merge initialQP section) and fix the !ctx->twopass < 1 typo. The first patch is fixing cuCtxCreate. I guess this patch and mine are almost the same excpet mine omits most of the log output. Agatha Hu --- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. --- ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 2/3] Optimize nvenc parameters, add 3 more presets: fast, medium, slow
From: ahu--- libavcodec/nvenc.c | 59 +++- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 3174b01..fd90f7b 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -610,8 +610,17 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) if (ctx->preset) { if (!strcmp(ctx->preset, "hp")) { encoder_preset = NV_ENC_PRESET_HP_GUID; +} else if (!strcmp(ctx->preset, "fast")) { +ctx->twopass = 0; +encoder_preset = NV_ENC_PRESET_HQ_GUID; } else if (!strcmp(ctx->preset, "hq")) { encoder_preset = NV_ENC_PRESET_HQ_GUID; +} else if (!strcmp(ctx->preset, "medium")) { +ctx->twopass = 0; +encoder_preset = NV_ENC_PRESET_HQ_GUID; +} else if (!strcmp(ctx->preset, "slow")) { +ctx->twopass = 1; +encoder_preset = NV_ENC_PRESET_HQ_GUID; } else if (!strcmp(ctx->preset, "bd")) { encoder_preset = NV_ENC_PRESET_BD_GUID; } else if (!strcmp(ctx->preset, "ll")) { @@ -632,7 +641,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } else if (!strcmp(ctx->preset, "default")) { encoder_preset = NV_ENC_PRESET_DEFAULT_GUID; } else { -av_log(avctx, AV_LOG_FATAL, "Preset \"%s\" is unknown! Supported presets: hp, hq, bd, ll, llhp, llhq, lossless, losslesshp, default\n", ctx->preset); +av_log(avctx, AV_LOG_FATAL, "Preset \"%s\" is unknown! Supported presets: slow, medium, fast, hp, hq, bd, ll, llhp, llhq, lossless, losslesshp, default\n", ctx->preset); res = AVERROR(EINVAL); goto error; } @@ -710,6 +719,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) switch (avctx->codec->id) { case AV_CODEC_ID_H264: ctx->encode_config.encodeCodecConfig.h264Config.maxNumRefFrames = avctx->refs; + ctx->encode_config.encodeCodecConfig.h264Config.hierarchicalPFrames = 1; break; case AV_CODEC_ID_H265: ctx->encode_config.encodeCodecConfig.hevcConfig.maxNumRefFramesInDPB = avctx->refs; @@ -770,7 +780,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) avctx->qmin = -1; avctx->qmax = -1; } else if (ctx->cbr) { -if (!ctx->twopass) { +if (ctx->twopass < 1) { ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CBR; } else if (ctx->twopass == 1 || isLL) { ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_QUALITY; @@ -799,7 +809,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) ctx->encode_config.encodeCodecConfig.h264Config.fmoMode = NV_ENC_H264_FMO_DISABLE; } } else { -ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR; +ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR_MINQP; } ctx->encode_config.rcParams.enableMinQP = 1; @@ -812,6 +822,45 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) ctx->encode_config.rcParams.maxQP.qpInterB = avctx->qmax; ctx->encode_config.rcParams.maxQP.qpInterP = avctx->qmax; ctx->encode_config.rcParams.maxQP.qpIntra = avctx->qmax; + +{ +uint32_t qpInterP = (avctx->qmax + 3*avctx->qmin)/4; // biased towards Qmin +ctx->encode_config.rcParams.initialRCQP.qpInterP = qpInterP; +if(avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) { +ctx->encode_config.rcParams.initialRCQP.qpIntra = qpInterP * fabs(avctx->i_quant_factor); +ctx->encode_config.rcParams.initialRCQP.qpIntra += qpInterP * (avctx->i_quant_offset); +ctx->encode_config.rcParams.initialRCQP.qpInterB = qpInterP * fabs(avctx->b_quant_factor); +ctx->encode_config.rcParams.initialRCQP.qpInterB += qpInterP * (avctx->b_quant_offset); +} else { +ctx->encode_config.rcParams.initialRCQP.qpIntra = qpInterP; +ctx->encode_config.rcParams.initialRCQP.qpInterB = qpInterP; +} +} +ctx->encode_config.rcParams.enableInitialRCQP = 1; +} else { +if (ctx->twopass < 1) { +ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR; +} else { +ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_VBR; +} + +{ +uint32_t qpInterP = 26; // default to 26 +ctx->encode_config.rcParams.initialRCQP.qpInterP = qpInterP; + +if(avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) { + +ctx->encode_config.rcParams.initialRCQP.qpIntra = qpInterP *
[FFmpeg-devel] [PATCH 1/3] change cuda ctx creation flag
From: agathah--- libavcodec/nvenc.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 5490652..3174b01 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -580,7 +580,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } ctx->cu_context = NULL; -cu_res = dl_fn->cu_ctx_create(>cu_context, 0, dl_fn->nvenc_devices[ctx->gpu]); +cu_res = dl_fn->cu_ctx_create(>cu_context, 4, dl_fn->nvenc_devices[ctx->gpu]); // CU_CTX_SCHED_BLOCKING_SYNC=4, avoid CPU spins if (cu_res != CUDA_SUCCESS) { av_log(avctx, AV_LOG_FATAL, "Failed creating CUDA context for NVENC: 0x%x\n", (int)cu_res); -- 1.7.9.5 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 3/3] merge compute initialQP sections
--- libavcodec/nvenc.c | 101 ++-- 1 file changed, 42 insertions(+), 59 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index fd90f7b..57aae33 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -800,69 +800,52 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) avctx->qmin = -1; avctx->qmax = -1; -} else if (avctx->qmin >= 0 && avctx->qmax >= 0) { -if (ctx->twopass == 1) { -ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_VBR; - -if (avctx->codec->id == AV_CODEC_ID_H264) { - ctx->encode_config.encodeCodecConfig.h264Config.adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE; -ctx->encode_config.encodeCodecConfig.h264Config.fmoMode = NV_ENC_H264_FMO_DISABLE; -} -} else { -ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR_MINQP; -} - -ctx->encode_config.rcParams.enableMinQP = 1; -ctx->encode_config.rcParams.enableMaxQP = 1; - -ctx->encode_config.rcParams.minQP.qpInterB = avctx->qmin; -ctx->encode_config.rcParams.minQP.qpInterP = avctx->qmin; -ctx->encode_config.rcParams.minQP.qpIntra = avctx->qmin; - -ctx->encode_config.rcParams.maxQP.qpInterB = avctx->qmax; -ctx->encode_config.rcParams.maxQP.qpInterP = avctx->qmax; -ctx->encode_config.rcParams.maxQP.qpIntra = avctx->qmax; - -{ -uint32_t qpInterP = (avctx->qmax + 3*avctx->qmin)/4; // biased towards Qmin -ctx->encode_config.rcParams.initialRCQP.qpInterP = qpInterP; -if(avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) { -ctx->encode_config.rcParams.initialRCQP.qpIntra = qpInterP * fabs(avctx->i_quant_factor); -ctx->encode_config.rcParams.initialRCQP.qpIntra += qpInterP * (avctx->i_quant_offset); -ctx->encode_config.rcParams.initialRCQP.qpInterB = qpInterP * fabs(avctx->b_quant_factor); -ctx->encode_config.rcParams.initialRCQP.qpInterB += qpInterP * (avctx->b_quant_offset); -} else { -ctx->encode_config.rcParams.initialRCQP.qpIntra = qpInterP; -ctx->encode_config.rcParams.initialRCQP.qpInterB = qpInterP; -} -} -ctx->encode_config.rcParams.enableInitialRCQP = 1; } else { -if (ctx->twopass < 1) { -ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR; -} else { -ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_VBR; +uint32_t qpInterP = 26; // default to 26 +if (avctx->qmin >= 0 && avctx->qmax >= 0) { +ctx->encode_config.rcParams.enableMinQP = 1; +ctx->encode_config.rcParams.enableMaxQP = 1; + +ctx->encode_config.rcParams.minQP.qpInterB = avctx->qmin; +ctx->encode_config.rcParams.minQP.qpInterP = avctx->qmin; +ctx->encode_config.rcParams.minQP.qpIntra = avctx->qmin; + +ctx->encode_config.rcParams.maxQP.qpInterB = avctx->qmax; +ctx->encode_config.rcParams.maxQP.qpInterP = avctx->qmax; +ctx->encode_config.rcParams.maxQP.qpIntra = avctx->qmax; +qpInterP = (avctx->qmax + 3*avctx->qmin)/4; // biased towards Qmin + +if (ctx->twopass == 1) { +ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_VBR; +if (avctx->codec->id == AV_CODEC_ID_H264) { + ctx->encode_config.encodeCodecConfig.h264Config.adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE; +ctx->encode_config.encodeCodecConfig.h264Config.fmoMode = NV_ENC_H264_FMO_DISABLE; +} +} else { +ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR_MINQP; +} } - -{ -uint32_t qpInterP = 26; // default to 26 -ctx->encode_config.rcParams.initialRCQP.qpInterP = qpInterP; - -if(avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) { - -ctx->encode_config.rcParams.initialRCQP.qpIntra = qpInterP * fabs(avctx->i_quant_factor); -ctx->encode_config.rcParams.initialRCQP.qpIntra += qpInterP * (avctx->i_quant_offset); - -ctx->encode_config.rcParams.initialRCQP.qpInterB = qpInterP * fabs(avctx->b_quant_factor); -ctx->encode_config.rcParams.initialRCQP.qpInterB += qpInterP * (avctx->b_quant_offset); +else { +if (ctx->twopass < 1) { +ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR; } else { -ctx->encode_config.rcParams.initialRCQP.qpIntra = qpInterP; -
[FFmpeg-devel] [PATCH] change flag of cuCtxCreate to avoid CPU spins
--- libavcodec/nvenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 7c683ea..a20356f 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -580,7 +580,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } ctx->cu_context = NULL; -cu_res = dl_fn->cu_ctx_create(>cu_context, 0, dl_fn->nvenc_devices[ctx->gpu]); +cu_res = dl_fn->cu_ctx_create(>cu_context, 4, dl_fn->nvenc_devices[ctx->gpu]); // CU_CTX_SCHED_BLOCKING_SYNC=4, avoid CPU spins if (cu_res != CUDA_SUCCESS) { av_log(avctx, AV_LOG_FATAL, "Failed creating CUDA context for NVENC: 0x%x\n", (int)cu_res); -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] Optimize nvenc parameters, add 3 more presets: fast, medium, slow
在 2015/9/10 17:48, Timo Rothenpieler 写道: @@ -770,7 +780,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) avctx->qmin = -1; avctx->qmax = -1; } else if (ctx->cbr) { -if (!ctx->twopass) { +if (!ctx->twopass < 1) { This doesn't seem right at all, what is it supposed to do? Keep in mind that twopass is a tristate, with the default beeing -1, which means autoselect. Sorry I made a mistake +if (!ctx->twopass < 1) { It should be +if (ctx->twopass < 1) { No wonder it doesn't seem right at all... Agatha Hu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] Optimize nvenc parameters, add 3 more presets: fast, medium, slow
if (ctx->twopass < 1) { This also seems a bit strange. +ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR; +} else { +ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_VBR; +} + +{ +uint32_t qpInterP = 26; // default to 26 +ctx->encode_config.rcParams.initialRCQP.qpInterP = qpInterP; + +if(avctx->i_quant_factor != 0.0 && avctx->b_quant_factor != 0.0) { + +ctx->encode_config.rcParams.initialRCQP.qpIntra = qpInterP * fabs(avctx->i_quant_factor); +ctx->encode_config.rcParams.initialRCQP.qpIntra += qpInterP * (avctx->i_quant_offset); + +ctx->encode_config.rcParams.initialRCQP.qpInterB = qpInterP * fabs(avctx->b_quant_factor); +ctx->encode_config.rcParams.initialRCQP.qpInterB += qpInterP * (avctx->b_quant_offset); +} else { +ctx->encode_config.rcParams.initialRCQP.qpIntra = qpInterP; +ctx->encode_config.rcParams.initialRCQP.qpInterB = qpInterP; +} +} +ctx->encode_config.rcParams.enableInitialRCQP = 1; } Can't this second block be merged with the first one? It seems to be doing the same calculations, just with a diffrent default value. if (avctx->rc_buffer_size > 0) @@ -1415,12 +1464,12 @@ static const enum AVPixelFormat pix_fmts_nvenc[] = { #define OFFSET(x) offsetof(NvencContext, x) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { -{ "preset", "Set the encoding preset (one of hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE }, +{ "preset", "Set the encoding preset (one of one of slow=hq 2pass, medium= hq, fast = hp, hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE }, { "profile", "Set the encoding profile (high, main or baseline)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "level", "Set the encoding level restriction (auto, 1.0, 1.0b, 1.1, 1.2, ..., 4.2, 5.0, 5.1)", OFFSET(level), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "tier", "Set the encoding tier (main or high)", OFFSET(tier), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, { "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, -{ "2pass", "Use 2pass cbr encoding mode", OFFSET(twopass), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, +{ "2pass", "Use 2pass encoding mode", OFFSET(twopass), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, { "gpu", "Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on.", OFFSET(gpu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE }, { "delay", "Delays frame output by the given amount of frames.", OFFSET(buffer_delay), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX, VE }, { NULL } * Unknown Key * 0xA6DA5D0F ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel I'll give you answer later. But there's a more urgent fix, I've sent the patch, only one-line changed. It's the creation flag of cuCtxCreate, currently is 0(default) which will cause CPU thread spins when waiting for GPU to return thus decrease the CPU performance. Change it to 4(CU_CTX_SCHED_BLOCKING_SYNC) could solve it. Agatha Hu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] Optimized parameters for NVENC
My colleagues recently optimized some initial parameter settings for nvenc extension, it improves the PSNR result by approximately 0.5dB. The main idea is assign some optimized initialQPs. I'll send the patch after integrate his improvement to nvenc.c ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] nvenc: Compensate for hardware trying to mess with aspect ratio of DVD content.
在 2015/1/22 12:29, Philip Langdale 写道: On Thu, 22 Jan 2015 12:15:44 +0800 Agatha Hu a...@nvidia.com wrote: We will fix the issue in driver, overscan compensation will be applied to input DAR *only* if the DAR is 4:3 or 16:9, otherwise won't unnecessarily modify the aspect ratio for resolutions like 720x480 and 720x576. The fix will be on future driver, I'll let you know when the branch is released. Please, no. We do not want overscan compensation to be done by nvenc at all. The compensation makes nvenc inconsistent with *all* other encoders in ffmpeg. For every other encoder, if my input is 720x576 at [64/45], then my output is the same. It does not do anyone any favours for nvenc to implicitly alter the output DAR. There is a separate discussion about whether DAR 'compensation' is desirable in an encoder or not, but even if that discussion results in a decision to apply DAR compensation at encode time, it will be done globally in ffmpeg for all encoders - ie: at a layer above any individual codec. If nvidia feels it is important to offer this compensation 'feature', then I would ask for a configuration option to turn it off - otherwise we will need the 'de-compensation' logic in the patch I posted. Thanks, --phil Disabling compensation is the best result, adding a flag is acceptable, but NVENC5.0 has just released, such option won't be available until 6.0 is available, so... Still waiting for nvenc teams feedback, the worst case is adding the 'de-compensation' logic for 4:3 and 16:9 Agatha Hu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] nvenc: Compensate for hardware trying to mess with aspect ratio of DVD content.
On 2015/1/21 16:00, Reimar Döffinger wrote: On 21.01.2015, at 07:17, Agatha Hu a...@nvidia.com wrote: On 2015/1/18 4:01, Philip Langdale wrote: Here's the reply from NVENC engineers It is not same thing as SAR. It is the display aspect ratio i.e width/height = DAR/SAR The calculation below should be like If (avctx-sample_aspect_ratio.num 0 avctx-sample_aspect_ratio.den 0 ) av_reduce(dw, dh, avctx-sample_aspect_ratio.num * avctx-width, avctx-sample_aspect_ratio.den * avctx-height, INT_MAX); That doesn't answer anything. Doing that, to keep the problem description short, creates different results from libx264 and any other encoder we have for DVD resolution which is highly undesirable for consistency and compatibility reasons if nothing else. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel We will fix the issue in driver, overscan compensation will be applied to input DAR *only* if the DAR is 4:3 or 16:9, otherwise won't unnecessarily modify the aspect ratio for resolutions like 720x480 and 720x576. The fix will be on future driver, I'll let you know when the branch is released. Agatha Hu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] avcodec/nvenc: add repeatSPSPPS flag for streaming
Still using attachment to prevent word-wrapping. For video streaming, repeatSPSPPS flag should be set as 1 besides disableSPSPPS=0, elsewise if running ffmpeg before vlc/ffmpeg, there will be no video header, decoder can't work properly. Agatha Hu From 526f4f37f1fbd8214a2866dad1d6c2ea480ffd9a Mon Sep 17 00:00:00 2001 From: agathah a...@nvidia.com Date: Wed, 21 Jan 2015 13:53:29 +0800 Subject: [PATCH] set repeatSPSPPS flag for streaming --- libavcodec/nvenc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 26f010e..7d82d58 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -683,6 +683,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) ctx-encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoFullRangeFlag = avctx-color_range == AVCOL_RANGE_JPEG; ctx-encode_config.encodeCodecConfig.h264Config.disableSPSPPS = (avctx-flags CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0; +ctx-encode_config.encodeCodecConfig.h264Config.repeatSPSPPS = (avctx-flags CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1; nv_status = p_nvenc-nvEncInitializeEncoder(ctx-nvencoder, ctx-init_encode_params); if (nv_status != NV_ENC_SUCCESS) { -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: fix dtspts when b frame = 1
On 2015/1/11 0:44, Michael Niedermayer wrote: * PGP Signed by an unknown key On Sat, Jan 10, 2015 at 05:30:03PM +0100, Timo Rothenpieler wrote: Looks good to merge for me. i wanted to apply it but the patch is corrupted Applying: avcodec/nvenc: fix dtspts when b frame = 1 fatal: corrupt patch at line 10 its so badly corrupted, even unwrap-diff cant fix it Agatha, please disable line/word wrap for patches or attach them and if that doesnt help use a different MUA / SMTP server whatever is causing this [...] Try using the attachment, if it still doesn't work, I'll use my gmail account to send it. Agatha Hu From cd62a0c47eb77f16efae25966b729c0f30852263 Mon Sep 17 00:00:00 2001 From: agathah a...@nvidia.com Date: Wed, 7 Jan 2015 17:19:32 +0800 Subject: [PATCH] fix b frame settings --- libavcodec/nvenc.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 345fb78..19a3ec8 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -657,9 +657,14 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } if (ctx-gobpattern = 0) { -ctx-encode_config.frameIntervalP = 1; + ctx-encode_config.frameIntervalP = ctx-gobpattern; } + // when there're b frames, set dts offset + if (ctx-encode_config.frameIntervalP = 2) { + ctx-last_dts = -2; + } + ctx-encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = 1; ctx-encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = 1; @@ -905,6 +910,10 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, AVFrame pkt-pts = lock_params.outputTimeStamp; pkt-dts = timestamp_queue_dequeue(ctx-timestamp_list); + // when there're b frame(s), set dts offset + if (ctx-encode_config.frameIntervalP = 2) + pkt-dts -= 1; + if (pkt-dts pkt-pts) pkt-dts = pkt-pts; -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] avcodec/nvenc: fix dtspts when b frame = 1
When B frames = 1, there'll be a invalid dts/pts warning during encoding like: [mp4 @ 0034cba0] Invalid DTS: 1024 PTS: 512 in output stream 0:0, replacing by guess [mp4 @ 0034cba0] Invalid DTS: 1536 PTS: 1024 in output stream 0:0, replacing by guess Set a -1 offset to dts to prevent dtspts case. From: agathah a...@nvidia.com --- libavcodec/nvenc.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 345fb78..19a3ec8 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -657,9 +657,14 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx) } if (ctx-gobpattern = 0) { -ctx-encode_config.frameIntervalP = 1; + ctx-encode_config.frameIntervalP = ctx-gobpattern; } +// when there're b frames, set dts offset +if (ctx-encode_config.frameIntervalP = 2) { +ctx-last_dts = -2; +} + ctx-encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = 1; ctx-encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = 1; @@ -905,6 +910,10 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, AVFrame pkt-pts = lock_params.outputTimeStamp; pkt-dts = timestamp_queue_dequeue(ctx-timestamp_list); +// when there're b frame(s), set dts offset +if (ctx-encode_config.frameIntervalP = 2) +pkt-dts -= 1; + if (pkt-dts pkt-pts) pkt-dts = pkt-pts; -- 1.9.5.github.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 4/4] nvenc: Try and do interlaced encoding.
On 2015/1/6 15:36, Philip Langdale wrote: Doesn't work. Signed-off-by: Philip Langdale phil...@overt.org --- libavcodec/libnvenc.c | 7 +++ libavcodec/libnvenc.h | 3 +++ libavcodec/nvencoder.c | 6 -- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libavcodec/libnvenc.c b/libavcodec/libnvenc.c index 3c64234..83587a6 100644 --- a/libavcodec/libnvenc.c +++ b/libavcodec/libnvenc.c @@ -189,6 +189,9 @@ static av_cold int ff_libnvenc_init(AVCodecContext *avctx) if (avctx-flags CODEC_FLAG_GLOBAL_HEADER) nvenc_ctx-nvenc_cfg.enableRepeatSPSPPS = 0; +if (avctx-flags CODEC_FLAG_INTERLACED_DCT) +nvenc_ctx-nvenc_cfg.interlaced = 1; + // Allocate list of x264 options x264_argc = 0; x264_argv = av_calloc(255, sizeof(char*)); @@ -299,6 +302,10 @@ static int ff_libnvenc_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFram nvenc_frame.width = avctx-width; nvenc_frame.height = avctx-height; nvenc_frame.format = map_avpixfmt_bufferformat(avctx-pix_fmt); +if (avctx-flags CODEC_FLAG_INTERLACED_DCT) { +nvenc_frame.interlaced = 1; +nvenc_frame.top_field_first = frame-top_field_first; +} } // Setup output diff --git a/libavcodec/libnvenc.h b/libavcodec/libnvenc.h index 63b5d67..76cb379 100644 --- a/libavcodec/libnvenc.h +++ b/libavcodec/libnvenc.h @@ -91,6 +91,7 @@ typedef struct nvenc_cfg_t uint32_tsliceMode; uint32_tsliceModeData; uint32_tdisableDeblockingFilterIDC; +boolinterlaced; // x264-style list of options char **x264_paramv; @@ -112,6 +113,8 @@ typedef struct nvenc_frame_t uint32_tframe_type; boolforce_idr; boolforce_intra; +boolinterlaced; +booltop_field_first; } nvenc_frame_t; /** diff --git a/libavcodec/nvencoder.c b/libavcodec/nvencoder.c index 2135f55..198ee09 100644 --- a/libavcodec/nvencoder.c +++ b/libavcodec/nvencoder.c @@ -478,7 +478,7 @@ static bool initialize(nvencoder_t *nvenc, nvenc_cfg_t *nvenc_cfg) nvenc-config.profileGUID = map_profile(nvenc_cfg-profile); nvenc-config.gopLength = nvenc_cfg-gopLength; nvenc-config.frameIntervalP= 1 + nvenc_cfg-numBFrames; -nvenc-config.frameFieldMode= NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME; +nvenc-config.frameFieldMode= nvenc_cfg-interlaced ? NV_ENC_PARAMS_FRAME_FIELD_MODE_FIELD : NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME; nvenc-config.mvPrecision = NV_ENC_MV_PRECISION_QUARTER_PEL; //NV_ENC_CODEC_CONFIG rate-control @@ -563,7 +563,9 @@ static bool encode_frame(nvencoder_t *nvenc, nvenc_frame_t *nvenc_frame, bool *o pic_params.inputBuffer = nvenc-i_buffer[nvenc-current_i % MAX_BUFFERS]; pic_params.outputBitstream = nvenc-o_buffer[nvenc-current_o % MAX_BUFFERS]; pic_params.bufferFmt = nvenc-buffer_fmt; -pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FRAME; +pic_params.pictureStruct = nvenc_frame-interlaced ? + nvenc_frame-top_field_first ? NV_ENC_PIC_STRUCT_FIELD_TOP_BOTTOM : NV_ENC_PIC_STRUCT_FIELD_BOTTOM_TOP : + NV_ENC_PIC_STRUCT_FRAME; pic_params.frameIdx= nvenc_frame-frame_idx; if (nvenc_frame-force_idr) pic_params.encodePicFlags |= NV_ENC_PIC_FLAG_FORCEIDR; OK let me take a look ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] ffmpeg nvenc
On 2014/12/29 22:10, Clément Bœsch wrote: I hope you understand that this patch is likely to get rejected for several reasons. Here is a (probably) non exhaustive list: - There are still some license uncertainties about the licensing (see die_license_disabled nonfree nvenc in the configure) - Having both libnvenc and nvenc is not viable. The users will be confused and a mess to maintain. If you want to replace nvenc by your code, make it support the same options as current nvenc (to not break compatibility), same name, and a feature equivalent or superset. The other solution being to patch our nvenc with the feature you want to add. And yes, NVIDIA will still have some visibility on this, you will be able to add yourself as maintainers for the file and in the Copyright header, if that's your company's concern. - You add many private unused options to make it compatible with a libx264 command line. This is messy; private options mean what they are, specific to the encoder. - Coding style is broken, you have many tabs, trailing whitespaces, ... Agatha Hu Regards, ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel Yes we plan to work on base of nvenc.c, libnvenc.patch is sent for comparison. Agatha Hu ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] ffmpeg nvenc
Repost -Original Message- From: Agatha Hu Sent: 2014年12月17日 15:49 To: 'Philip Langdale'; 'ffmpeg-devel@ffmpeg.org' Cc: Abhijit Patait; Eric Young; Jaime Ieong; Andrew Fear; Stephen Warren; Andy Ritger Subject: RE: ffmpeg nvenc Hi Phil, We've almost finished the license part in our patch and plan to commit to ffmpeg community, but we found ffmpeg add Timo's nvenc patch days ago, so our patch is incompatible with the TOT version. Should we (1)Add libnvenc on TOT branch but without changing Timo's work or (2)Change nvenc on TOT branch like an incremental patch on Timo's work. In fact I would prefer (1), as it requires less work. Agatha Hu -Original Message- From: Philip Langdale [mailto:phil...@overt.org] Sent: 2014年12月1日 15:04 To: Agatha Hu Cc: Abhijit Patait; Eric Young; Jaime Ieong; Andrew Fear; Stephen Warren Subject: Re: ffmpeg nvenc Sure thing. Thanks, --phil On Mon, 1 Dec 2014 02:59:42 + Agatha Hu a...@nvidia.com wrote: Hi Phil, we're discussing internally, I'll let you know when we finish the legal issue. -Original Message- From: Philip Langdale [mailto:phil...@overt.org] Sent: 2014年11月29日 2:39 To: Abhijit Patait Cc: Agatha Hu; Eric Young; Jaime Ieong; Stephen Warren; Andrew Fear Subject: Re: ffmpeg nvenc And FYI, someone has posted an independent implementation of nvenc support to the ffmpeg-devel mailing list. http://www.mail-archive.com/ffmpeg-devel@ffmpeg.org/msg06257.html It's simpler than your version, but I think there's a lot of virtue in your attempt at mapping the x264 configuration options. You guys should get engaged in the conversation. --phil On Thu, 27 Nov 2014 06:15:21 + Abhijit Patait apat...@nvidia.com wrote: +Andrew -Original Message- From: Philip Langdale [mailto:phil...@overt.org] Sent: Wednesday, November 26, 2014 10:57 AM To: Agatha Hu Cc: Eric Young; Jaime Ieong; Abhijit Patait; Stephane Warnon Subject: Re: ffmpeg nvenc On Tue, 25 Nov 2014 05:28:36 + Agatha Hu a...@nvidia.com wrote: +more people I guess at first we plan to release it as a patch to ffmpeg forum? No, the code was first developed by Jaime, I don't think Stephane knew the detail. And there's no tracking internally because of some license issue. As ffmpeg is open-sourced gnu project, but nvenc is not, it only provides header and dll. So, to get this accepted, all the files in the ffmpeg patch need to be licensed as LGPL 2.1 (or later). nvEncoder.h and cuda.h are separate, but due to their licensing, the nvenc feature would need to be part of the 'nonfree' set of ffmpeg functionality (which I see is already in the patch). --phil Agatha Hu -Original Message- From: Philip Langdale [mailto:phil...@overt.org] Sent: 2014年11月25日 13:14 To: Agatha Hu Subject: Re: ffmpeg nvenc Hi Agatha, First off, it's great that you've been working on the nvenc-ffmpeg integration - I've already found it to be very effective! And so I'm very keen to see it get merged into upstream ffmpeg - but without clear licensing, the current patch won't get accepted. Stephen Warren at nvidia did a lot of the work on the VDPAU patches for ffmpeg, so he's got experience working with them and getting code merged. Have you talked to him about this? If not, I'd highly recommend it. As I said, I've got a handful of improvements I'd like to feed back to you, and github is fine for this, but I don't know what your plans and whether you're already tackling these things. I've got fixes for setting the right aspect ratio (although this involved some black magic) and correctly handling b-frames. Thanks, --phil On Tue, 25 Nov 2014 10:22:58 +0800 agatha Hu agatha...@gmail.com wrote: Hi Phillip, yes I'm working in NVIDIA, can you contact me with a...@nvidia.com? Thanks 2014-11-25 0:21 GMT+08:00 Philip Langdale phil...@overt.org: Hi, I saw that you published a git repo with basic nvenc suport on github, and I've been playing with it over the weekend, and making some improvements like b-frame support, but the licensing of the code is very unclear - some files have an NVIDIA copyright on them and libnvenc.c has no licence on it at all. In this state, it will never be possible to merge it into upstream ffmpeg. The NVIDIA copyrighted files are not ones that I've seen anywhere else, so they don't look like public sample code. Do you work for NVIDIA? Anyway, I'd like to try and get the nvenc support merged (and I have experience writing a new codec for ffmpeg and getting that merged) but licence clarification is the first key step. Thanks! --phil --phil --phil