From: Zhao Zhili <quinkblack-at-foxmail.com@ffmpeg.org> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: Timo Rothenpieler <timo@rothenpieler.org> Subject: Re: [FFmpeg-devel] [PATCH 8/9] avcodec/nvenc: use encoder level options for qmin/qmax Date: Fri, 31 Jan 2025 14:16:06 +0800 Message-ID: <tencent_2034893E25578D9DD0E1D65A0034B7801C09@qq.com> (raw) In-Reply-To: <20250130194124.21836-9-timo@rothenpieler.org> > On Jan 31, 2025, at 03:40, Timo Rothenpieler <timo@rothenpieler.org> wrote: > > AV1 uses a vastly different range than what the global options permit, > and also for the other codecs the range of the global options is at > least misaligned. It ’s simpler to update qmin upper threshold than add qmin/qmax for each encoder. And there is no mismatch issue between global options and local options. > > Fixes #11365 > --- > libavcodec/nvenc.c | 49 +++++++++++++++++++++++++---------------- > libavcodec/nvenc.h | 2 ++ > libavcodec/nvenc_av1.c | 4 ++++ > libavcodec/nvenc_h264.c | 4 ++++ > libavcodec/nvenc_hevc.c | 4 ++++ > 5 files changed, 44 insertions(+), 19 deletions(-) > > diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c > index a528f1ce93..a5c507150c 100644 > --- a/libavcodec/nvenc.c > +++ b/libavcodec/nvenc.c > @@ -893,8 +893,8 @@ 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, qmax); > } > > - avctx->qmin = -1; > - avctx->qmax = -1; > + avctx->qmin = ctx->qmin = -1; > + avctx->qmax = ctx->qmax = -1; > } > > static av_cold void set_vbr(AVCodecContext *avctx) > @@ -908,27 +908,37 @@ static av_cold void set_vbr(AVCodecContext *avctx) > int qmax = 51; > #endif > > - if (avctx->qmin >= 0 && avctx->qmax >= 0) { > + if (avctx->qmin >= 0 || avctx->qmax >= 0) > + av_log(avctx, AV_LOG_WARNING, "Passing qmin/qmax via global AVCodecContext options. Use encoder options instead.\n"); > + > + if (avctx->qmin >= 0 && ctx->qmin < 0) > + ctx->qmin = avctx->qmin; > + if (avctx->qmax >= 0 && ctx->qmax < 0) > + ctx->qmax = avctx->qmax; > + avctx->qmin = ctx->qmin; > + avctx->qmax = ctx->qmax; > + > + if (ctx->qmin >= 0 && ctx->qmax >= 0) { > rc->enableMinQP = 1; > rc->enableMaxQP = 1; > > - rc->minQP.qpInterB = avctx->qmin; > - rc->minQP.qpInterP = avctx->qmin; > - rc->minQP.qpIntra = avctx->qmin; > + rc->minQP.qpInterB = ctx->qmin; > + rc->minQP.qpInterP = ctx->qmin; > + rc->minQP.qpIntra = ctx->qmin; > > - rc->maxQP.qpInterB = avctx->qmax; > - rc->maxQP.qpInterP = avctx->qmax; > - rc->maxQP.qpIntra = avctx->qmax; > + rc->maxQP.qpInterB = ctx->qmax; > + rc->maxQP.qpInterP = ctx->qmax; > + rc->maxQP.qpIntra = ctx->qmax; > > - qp_inter_p = (avctx->qmax + 3 * avctx->qmin) / 4; // biased towards Qmin > - } else if (avctx->qmin >= 0) { > + qp_inter_p = (ctx->qmax + 3 * ctx->qmin) / 4; // biased towards Qmin > + } else if (ctx->qmin >= 0) { > rc->enableMinQP = 1; > > - rc->minQP.qpInterB = avctx->qmin; > - rc->minQP.qpInterP = avctx->qmin; > - rc->minQP.qpIntra = avctx->qmin; > + rc->minQP.qpInterB = ctx->qmin; > + rc->minQP.qpInterP = ctx->qmin; > + rc->minQP.qpIntra = ctx->qmin; > > - qp_inter_p = avctx->qmin; > + qp_inter_p = ctx->qmin; > } else { > qp_inter_p = 26; // default to 26 > } > @@ -974,8 +984,8 @@ static av_cold void set_lossless(AVCodecContext *avctx) > rc->constQP.qpInterP = 0; > rc->constQP.qpIntra = 0; > > - avctx->qmin = -1; > - avctx->qmax = -1; > + avctx->qmin = ctx->qmin = -1; > + avctx->qmax = ctx->qmax = -1; > } > > static void nvenc_override_rate_control(AVCodecContext *avctx) > @@ -989,7 +999,7 @@ static void nvenc_override_rate_control(AVCodecContext *avctx) > return; > #ifndef NVENC_NO_DEPRECATED_RC > case NV_ENC_PARAMS_RC_VBR_MINQP: > - if (avctx->qmin < 0) { > + if (avctx->qmin < 0 && ctx->qmin < 0) { > av_log(avctx, AV_LOG_WARNING, > "The variable bitrate rate-control requires " > "the 'qmin' option set.\n"); > @@ -1112,7 +1122,8 @@ static av_cold int nvenc_setup_rate_control(AVCodecContext *avctx) > ctx->rc = NV_ENC_PARAMS_RC_CONSTQP; > } else if (ctx->twopass) { > ctx->rc = NV_ENC_PARAMS_RC_VBR_HQ; > - } else if (avctx->qmin >= 0 && avctx->qmax >= 0) { > + } else if ((avctx->qmin >= 0 && avctx->qmax >= 0) || > + (ctx->qmin >= 0 && ctx->qmax >= 0)) { > ctx->rc = NV_ENC_PARAMS_RC_VBR_MINQP; > } > } > diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h > index 77aef3f188..f84adbdd55 100644 > --- a/libavcodec/nvenc.h > +++ b/libavcodec/nvenc.h > @@ -273,6 +273,8 @@ typedef struct NvencContext > float quality; > int aud; > int bluray_compat; > + int qmin; > + int qmax; > int init_qp_p; > int init_qp_b; > int init_qp_i; > diff --git a/libavcodec/nvenc_av1.c b/libavcodec/nvenc_av1.c > index 5dd27fe872..ceb046e4be 100644 > --- a/libavcodec/nvenc_av1.c > +++ b/libavcodec/nvenc_av1.c > @@ -119,6 +119,10 @@ static const AVOption options[] = { > 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 }, > + { "qmin", "Specifies the minimum QP used for rate control", > + OFFSET(qmin), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 255, VE }, > + { "qmax", "Specifies the maximum QP used for rate control", > + OFFSET(qmax), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 255, VE }, > { "no-scenecut", "When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts", > OFFSET(no_scenecut), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, > { "forced-idr", "If forcing keyframes, force them as IDR frames.", > diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c > index 5e9f73412f..c7267a082a 100644 > --- a/libavcodec/nvenc_h264.c > +++ b/libavcodec/nvenc_h264.c > @@ -174,6 +174,10 @@ static const AVOption options[] = { > 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 }, > + { "qmin", "Specifies the minimum QP used for rate control", > + OFFSET(qmin), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51, VE }, > + { "qmax", "Specifies the maximum QP used for rate control", > + OFFSET(qmax), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51, 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, .unit = "coder" }, > diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c > index f821eaee50..f1b7062902 100644 > --- a/libavcodec/nvenc_hevc.c > +++ b/libavcodec/nvenc_hevc.c > @@ -158,6 +158,10 @@ static const AVOption options[] = { > 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 }, > + { "qmin", "Specifies the minimum QP used for rate control", > + OFFSET(qmin), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51, VE }, > + { "qmax", "Specifies the maximum QP used for rate control", > + OFFSET(qmax), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51, 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 > -- > 2.45.2 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-01-31 6:16 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-01-30 19:40 [FFmpeg-devel] [PATCH 0/9] Nvidia Video Codec SDK 13.0 support Timo Rothenpieler 2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 1/9] avutil/hwcontext_cuda: add 4:2:2 pixel format support Timo Rothenpieler 2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 2/9] avcodec/nvdec: add 4:2:2 decoding and 10-bit support Timo Rothenpieler 2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 3/9] avcodec/cuviddec: add HEVC/H.264 4:2:2 and H.264 " Timo Rothenpieler 2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 4/9] avcodec/nvenc: add 4:2:2 encoding " Timo Rothenpieler 2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 5/9] avcodec/nvenc: add UHQ to AV1 for NVENC Timo Rothenpieler 2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 6/9] avcodec/nvenc: add Temporal Filtering for AV1 and H.264 in NVENC Timo Rothenpieler 2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 7/9] avcodec/nvenc: add MV-HEVC encoding support Timo Rothenpieler 2025-01-30 20:17 ` James Almer 2025-01-30 23:23 ` [FFmpeg-devel] [PATCH v2 " Timo Rothenpieler 2025-01-31 3:26 ` James Almer 2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 8/9] avcodec/nvenc: use encoder level options for qmin/qmax Timo Rothenpieler 2025-01-31 6:16 ` Zhao Zhili [this message] 2025-01-31 13:20 ` Timo Rothenpieler 2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 9/9] avcodec/nvenc: finalize SDK 13.0 support Timo Rothenpieler 2025-02-01 21:15 ` [FFmpeg-devel] [PATCH 0/9] Nvidia Video Codec " Timo Rothenpieler 2025-02-02 19:05 ` Timo Rothenpieler
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=tencent_2034893E25578D9DD0E1D65A0034B7801C09@qq.com \ --to=quinkblack-at-foxmail.com@ffmpeg.org \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=timo@rothenpieler.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git