| @@ -884,8 +884,8 @@ static av_cold void set_constqp(AVCodecContext *avctx) · 883 unmodified lines |
| 884 | 884 | rc->constQP.qpIntra = av_clip(ctx->cqp * fabs(avctx->i_quant_factor) + avctx->i_quant_offset + 0.5, 0, qmax); |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | | − avctx->qmin = -1; |
| 888 | | − avctx->qmax = -1; |
| 887 | + avctx->qmin = ctx->qmin = -1; |
| 888 | + avctx->qmax = ctx->qmax = -1; |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | static av_cold void set_vbr(AVCodecContext *avctx) |
| @@ -899,27 +899,37 @@ static av_cold void set_vbr(AVCodecContext *avctx) · 7 unmodified lines |
| 899 | 899 | int qmax = 51; |
| 900 | 900 | #endif |
| 901 | 901 | |
| 902 | | − if (avctx->qmin >= 0 && avctx->qmax >= 0) { |
| 902 | + if (avctx->qmin >= 0 || avctx->qmax >= 0) |
| 903 | + av_log(avctx, AV_LOG_WARNING, "Passing qmin/qmax via global AVCodecContext options. Use encoder options instead.\n"); |
| 904 | + |
| 905 | + if (avctx->qmin >= 0 && ctx->qmin < 0) |
| 906 | + ctx->qmin = avctx->qmin; |
| 907 | + if (avctx->qmax >= 0 && ctx->qmax < 0) |
| 908 | + ctx->qmax = avctx->qmax; |
| 909 | + avctx->qmin = ctx->qmin; |
| 910 | + avctx->qmax = ctx->qmax; |
| 911 | + |
| 912 | + if (ctx->qmin >= 0 && ctx->qmax >= 0) { |
| 903 | 913 | rc->enableMinQP = 1; |
| 904 | 914 | rc->enableMaxQP = 1; |
| 905 | 915 | |
| 906 | | − rc->minQP.qpInterB = avctx->qmin; |
| 907 | | − rc->minQP.qpInterP = avctx->qmin; |
| 908 | | − rc->minQP.qpIntra = avctx->qmin; |
| 916 | + rc->minQP.qpInterB = ctx->qmin; |
| 917 | + rc->minQP.qpInterP = ctx->qmin; |
| 918 | + rc->minQP.qpIntra = ctx->qmin; |
| 909 | 919 | |
| 910 | | − rc->maxQP.qpInterB = avctx->qmax; |
| 911 | | − rc->maxQP.qpInterP = avctx->qmax; |
| 912 | | − rc->maxQP.qpIntra = avctx->qmax; |
| 920 | + rc->maxQP.qpInterB = ctx->qmax; |
| 921 | + rc->maxQP.qpInterP = ctx->qmax; |
| 922 | + rc->maxQP.qpIntra = ctx->qmax; |
| 913 | 923 | |
| 914 | | − qp_inter_p = (avctx->qmax + 3 * avctx->qmin) / 4; // biased towards Qmin |
| 915 | | − } else if (avctx->qmin >= 0) { |
| 924 | + qp_inter_p = (ctx->qmax + 3 * ctx->qmin) / 4; // biased towards Qmin |
| 925 | + } else if (ctx->qmin >= 0) { |
| 916 | 926 | rc->enableMinQP = 1; |
| 917 | 927 | |
| 918 | | − rc->minQP.qpInterB = avctx->qmin; |
| 919 | | − rc->minQP.qpInterP = avctx->qmin; |
| 920 | | − rc->minQP.qpIntra = avctx->qmin; |
| 928 | + rc->minQP.qpInterB = ctx->qmin; |
| 929 | + rc->minQP.qpInterP = ctx->qmin; |
| 930 | + rc->minQP.qpIntra = ctx->qmin; |
| 921 | 931 | |
| 922 | | − qp_inter_p = avctx->qmin; |
| 932 | + qp_inter_p = ctx->qmin; |
| 923 | 933 | } else { |
| 924 | 934 | qp_inter_p = 26; // default to 26 |
| 925 | 935 | } |
| @@ -965,8 +975,8 @@ static av_cold void set_lossless(AVCodecContext *avctx) · 39 unmodified lines |
| 965 | 975 | rc->constQP.qpInterP = 0; |
| 966 | 976 | rc->constQP.qpIntra = 0; |
| 967 | 977 | |
| 968 | | − avctx->qmin = -1; |
| 969 | | − avctx->qmax = -1; |
| 978 | + avctx->qmin = ctx->qmin = -1; |
| 979 | + avctx->qmax = ctx->qmax = -1; |
| 970 | 980 | } |
| 971 | 981 | |
| 972 | 982 | static void nvenc_override_rate_control(AVCodecContext *avctx) |
| @@ -980,7 +990,7 @@ static void nvenc_override_rate_control(AVCodecContext *avctx) · 7 unmodified lines |
| 980 | 990 | return; |
| 981 | 991 | #ifndef NVENC_NO_DEPRECATED_RC |
| 982 | 992 | case NV_ENC_PARAMS_RC_VBR_MINQP: |
| 983 | | − if (avctx->qmin < 0) { |
| 993 | + if (avctx->qmin < 0 && ctx->qmin < 0) { |
| 984 | 994 | av_log(avctx, AV_LOG_WARNING, |
| 985 | 995 | "The variable bitrate rate-control requires " |
| 986 | 996 | "the 'qmin' option set.\n"); |
| @@ -1103,7 +1113,8 @@ static av_cold int nvenc_setup_rate_control(AVCodecContext *avctx) · 116 unmodified lines |
| 1103 | 1113 | ctx->rc = NV_ENC_PARAMS_RC_CONSTQP; |
| 1104 | 1114 | } else if (ctx->twopass) { |
| 1105 | 1115 | ctx->rc = NV_ENC_PARAMS_RC_VBR_HQ; |
| 1106 | | − } else if (avctx->qmin >= 0 && avctx->qmax >= 0) { |
| 1116 | + } else if ((avctx->qmin >= 0 && avctx->qmax >= 0) || |
| 1117 | + (ctx->qmin >= 0 && ctx->qmax >= 0)) { |
| 1107 | 1118 | ctx->rc = NV_ENC_PARAMS_RC_VBR_MINQP; |
| 1108 | 1119 | } |
| 1109 | 1120 | } |