<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 15, 2016 at 7:03 PM, <span dir="ltr"><<a href="mailto:gopi.satykrishna@multicorewareinc.com" target="_blank">gopi.satykrishna@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Gopi Satykrishna Akisetty <<a href="mailto:gopi.satykrishna@multicorewareinc.com">gopi.satykrishna@multicorewareinc.com</a>><br>
# Date 1468581281 -19800<br>
# Fri Jul 15 16:44:41 2016 +0530<br>
# Node ID 98a948623fdc745a37123f52a00fefeecaadaad7<br>
# Parent 43ca544799c240f6eefb66424dc73ec65b7dcfea<br>
rc: add qpmin and qpmax options<br>
<br>
diff -r 43ca544799c2 -r 98a948623fdc doc/reST/cli.rst<br>
--- a/doc/reST/cli.rst Fri Jul 15 12:43:23 2016 +0530<br>
+++ b/doc/reST/cli.rst Fri Jul 15 16:44:41 2016 +0530<br>
@@ -1434,6 +1434,14 @@<br>
The maximum single adjustment in QP allowed to rate control. Default<br>
4<br>
<br>
+.. option:: --qpmin <integer><br>
+<br>
+ sets a hard lower limit on QP allowed to ratecontrol. Default 0<br>
+<br>
+.. option:: --qpmax <integer><br>
+<br>
+ sets a hard upper limit on QP allowed to ratecontrol. Default 69<br>
+<br>
.. option:: --rc-grain, --no-rc-grain<br>
<br>
Enables a specialised ratecontrol algorithm for film grain content. This<br>
diff -r 43ca544799c2 -r 98a948623fdc source/CMakeLists.txt<br>
--- a/source/CMakeLists.txt Fri Jul 15 12:43:23 2016 +0530<br>
+++ b/source/CMakeLists.txt Fri Jul 15 16:44:41 2016 +0530<br>
@@ -30,7 +30,7 @@<br>
mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br>
<br>
# X265_BUILD must be incremented each time the public API is changed<br>
-set(X265_BUILD 88)<br>
+set(X265_BUILD 89)<br>
configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265.def.in" rel="noreferrer" target="_blank">x265.def.in</a>"<br>
"${PROJECT_BINARY_DIR}/x265.def")<br>
configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265_config.h.in" rel="noreferrer" target="_blank">x265_config.h.in</a>"<br>
diff -r 43ca544799c2 -r 98a948623fdc source/common/param.cpp<br>
--- a/source/common/param.cpp Fri Jul 15 12:43:23 2016 +0530<br>
+++ b/source/common/param.cpp Fri Jul 15 16:44:41 2016 +0530<br>
@@ -224,6 +224,8 @@<br>
param->rc.bEnableSlowFirstPass = 1;<br>
param->rc.bStrictCbr = 0;<br>
param->rc.bEnableGrain = 0;<br>
+ param->rc.qpMin = 0;<br>
+ param->rc.qpMax = QP_MAX_MAX;<br>
<br>
/* Video Usability Information (VUI) */<br>
param->vui.aspectRatioIdc = 0;<br>
@@ -509,6 +511,7 @@<br>
bool bError = false;<br>
bool bNameWasBool = false;<br>
bool bValueWasNull = !value;<br>
+ bool bExtraParams = false;<br>
char nameBuf[64];<br>
<br>
if (!name)<br>
@@ -747,6 +750,7 @@<br>
OPT("vbv-init") p->rc.vbvBufferInit = atof(value);<br>
OPT("crf-max") p->rc.rfConstantMax = atof(value);<br>
OPT("crf-min") p->rc.rfConstantMin = atof(value);<br>
+ OPT("qpmax") p->rc.qpMax = atoi(value);<br>
OPT("crf")<br>
{<br>
p->rc.rfConstant = atof(value);<br>
@@ -885,7 +889,14 @@<br>
OPT("max-luma") p->maxLuma = (uint16_t)atoi(value);<br>
OPT("uhd-bd") p->uhdBluray = atobool(value);<br>
else<br>
- return X265_PARAM_BAD_NAME;<br>
+ bExtraParams = true;<br>
+ if (bExtraParams)<br>
+ {<br>
+ if (0) ;<br>
+ OPT("qpmin") p->rc.qpMin = atoi(value);<br>
+ else<br>
+ return X265_PARAM_BAD_NAME;<br>
+ }<br>
#undef OPT<br>
#undef atobool<br>
#undef atoi<br>
@@ -1208,6 +1219,10 @@<br>
"Strict-cbr cannot be applied without specifying target bitrate or vbv bufsize");<br>
CHECK(param->analysisMode && (param->analysisMode < X265_ANALYSIS_OFF || param->analysisMode > X265_ANALYSIS_LOAD),<br>
"Invalid analysis mode. Analysis mode 0: OFF 1: SAVE : 2 LOAD");<br>
+ CHECK(param->rc.qpMax < QP_MIN || param->rc.qpMax > QP_MAX_MAX,<br>
+ "qpmax exceeds supported range (0 to 69)");<br>
+ CHECK(param->rc.qpMin < QP_MIN || param->rc.qpMin > QP_MAX_MAX,<br>
+ "qpmin exceeds supported range (0 to 69)");<br>
return check_failed;<br>
}<br>
<br>
@@ -1463,7 +1478,7 @@<br>
else<br>
s += sprintf(s, " bitrate=%d", p->rc.bitrate);<br>
s += sprintf(s, " qcomp=%.2f qpmin=%d qpmax=%d qpstep=%d",<br>
- p->rc.qCompress, QP_MIN, QP_MAX_SPEC, p->rc.qpStep);<br>
+ p->rc.qCompress, p->rc.qpMin, p->rc.qpMax, p->rc.qpStep);<br></blockquote><div><br></div><div>I suggest you print this only if they are different from the defaults, to avoid cluttering up the console output.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
if (p->rc.bStatRead)<br>
s += sprintf( s, " cplxblur=%.1f qblur=%.1f",<br>
p->rc.complexityBlur, p->rc.qblur);<br>
diff -r 43ca544799c2 -r 98a948623fdc source/encoder/analysis.cpp<br>
--- a/source/encoder/analysis.cpp Fri Jul 15 12:43:23 2016 +0530<br>
+++ b/source/encoder/analysis.cpp Fri Jul 15 16:44:41 2016 +0530<br>
@@ -255,7 +255,7 @@<br>
cuPrevCost = origCUCost;<br>
<br>
int modCUQP = qp + dir;<br>
- while (modCUQP >= QP_MIN && modCUQP <= QP_MAX_SPEC)<br>
+ while (modCUQP >= m_param->rc.qpMin && modCUQP <= QP_MAX_SPEC)<br></blockquote><div><br></div><div>This should be qpMax? <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
{<br>
recodeCU(parentCTU, cuGeom, modCUQP, qp);<br>
cuCost = md.bestMode->rdCost;<br>
@@ -2667,5 +2667,5 @@<br>
qp += qp_offset;<br>
}<br>
<br>
- return x265_clip3(QP_MIN, QP_MAX_MAX, (int)(qp + 0.5));<br>
+ return x265_clip3(m_param->rc.qpMin, m_param->rc.qpMax, (int)(qp + 0.5));<br>
}<br>
diff -r 43ca544799c2 -r 98a948623fdc source/encoder/frameencoder.cpp<br>
--- a/source/encoder/frameencoder.cpp Fri Jul 15 12:43:23 2016 +0530<br>
+++ b/source/encoder/frameencoder.cpp Fri Jul 15 16:44:41 2016 +0530<br>
@@ -1127,7 +1127,7 @@<br>
{<br>
double qpBase = curEncData.m_cuStat[cuAddr].baseQp;<br>
int reEncode = m_top->m_rateControl->rowDiagonalVbvRateControl(m_frame, row, &m_rce, qpBase);<br>
- qpBase = x265_clip3((double)QP_MIN, (double)QP_MAX_MAX, qpBase);<br>
+ qpBase = x265_clip3((double)m_param->rc.qpMin, (double)m_param->rc.qpMax, qpBase);<br>
curEncData.m_rowStat[row].diagQp = qpBase;<br>
curEncData.m_rowStat[row].diagQpScale = x265_qp2qScale(qpBase);<br>
<br>
diff -r 43ca544799c2 -r 98a948623fdc source/encoder/ratecontrol.cpp<br>
--- a/source/encoder/ratecontrol.cpp Fri Jul 15 12:43:23 2016 +0530<br>
+++ b/source/encoder/ratecontrol.cpp Fri Jul 15 16:44:41 2016 +0530<br>
@@ -284,7 +284,11 @@<br>
#define ABR_SCENECUT_INIT_QP_MIN (12)<br>
#define CRF_INIT_QP (int)m_param->rc.rfConstant<br>
for (int i = 0; i < 3; i++)<br>
+ {<br>
m_lastQScaleFor[i] = x265_qp2qScale(m_param->rc.rateControlMode == X265_RC_CRF ? CRF_INIT_QP : ABR_INIT_QP_MIN);<br>
+ m_lmin[i] = x265_qp2qScale(m_param->rc.qpMin);<br>
+ m_lmax[i] = x265_qp2qScale(m_param->rc.qpMax);<br>
+ }<br>
<br>
if (m_param->rc.rateControlMode == X265_RC_CQP)<br>
{<br>
@@ -808,13 +812,19 @@<br>
(double)m_param->rc.bitrate,<br>
expectedBits * m_fps / (m_numEntries * 1000.),<br>
avgq);<br>
- if (expectedBits < allAvailableBits && avgq < QP_MIN + 2)<br>
+ if (expectedBits < allAvailableBits && avgq < m_param->rc.qpMin + 2)<br>
{<br>
- x265_log(m_param, X265_LOG_WARNING, "try reducing target bitrate\n");<br>
+ if (m_param->rc.qpMin > 0)<br>
+ x265_log(m_param, X265_LOG_WARNING, "try reducing target bitrate or reducing qp_min (currently %d)\n", m_param->rc.qpMin);<br>
+ else<br>
+ x265_log(m_param, X265_LOG_WARNING, "try reducing target bitrate\n");<br>
}<br>
- else if (expectedBits > allAvailableBits && avgq > QP_MAX_SPEC - 2)<br>
+ else if (expectedBits > allAvailableBits && avgq > m_param->rc.qpMax - 2)<br>
{<br>
- x265_log(m_param, X265_LOG_WARNING, "try increasing target bitrate\n");<br>
+ if (m_param->rc.qpMax < QP_MAX_MAX)<br>
+ x265_log(m_param, X265_LOG_WARNING, "try increasing target bitrate or increasing qp_max (currently %d)\n", m_param->rc.qpMax);<br>
+ else<br>
+ x265_log(m_param, X265_LOG_WARNING, "try increasing target bitrate\n");<br>
}<br>
else if (!(m_2pass && m_isVbv))<br>
x265_log(m_param, X265_LOG_WARNING, "internal error\n");<br>
@@ -966,6 +976,8 @@<br>
double adjustment;<br>
double prevBits = 0;<br>
int t0, t1;<br>
+ double qScaleMin = x265_qp2qScale(m_param->rc.qpMin);<br>
+ double qScaleMax = x265_qp2qScale(m_param->rc.qpMax);<br>
int iterations = 0 , adjMin, adjMax;<br>
CHECKED_MALLOC(fills, double, m_numEntries + 1);<br>
fills++;<br>
@@ -985,7 +997,7 @@<br>
adjMin = 1;<br>
while (adjMin && findUnderflow(fills, &t0, &t1, 1, endPos))<br>
{<br>
- adjMin = fixUnderflow(t0, t1, adjustment, MIN_QPSCALE, MAX_MAX_QPSCALE);<br>
+ adjMin = fixUnderflow(t0, t1, adjustment, qScaleMin, qScaleMax);<br>
t0 = t1;<br>
}<br>
}<br>
@@ -995,7 +1007,7 @@<br>
/* fix underflows -- should be done after overflow, as we'd better undersize target than underflowing VBV */<br>
adjMax = 1;<br>
while (adjMax && findUnderflow(fills, &t0, &t1, 0, endPos))<br>
- adjMax = fixUnderflow(t0, t1, 1.001, MIN_QPSCALE, MAX_MAX_QPSCALE );<br>
+ adjMax = fixUnderflow(t0, t1, 1.001, qScaleMin, qScaleMax);<br>
expectedBits = countExpectedBits(startPos, endPos);<br>
}<br>
while ((expectedBits < .995 * allAvailableBits) && ((int64_t)(expectedBits+.5) > (int64_t)(prevBits+.5)) && !(m_param->rc.rateControlMode == X265_RC_CRF));<br>
@@ -1216,7 +1228,7 @@<br>
* the scene-transition mini-gop */<br>
<br>
double q = x265_qScale2qp(rateEstimateQscale(curFrame, rce));<br>
- q = x265_clip3((double)QP_MIN, (double)QP_MAX_MAX, q);<br>
+ q = x265_clip3((double)m_param->rc.qpMin, (double)m_param->rc.qpMax, q);<br>
m_qp = int(q + 0.5);<br>
q = m_isGrainEnabled ? m_qp : q;<br>
rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = q;<br>
@@ -1254,7 +1266,7 @@<br>
if (curFrame->m_forceqp)<br>
{<br>
m_qp = (int32_t)(curFrame->m_forceqp + 0.5) - 1;<br>
- m_qp = x265_clip3(QP_MIN, QP_MAX_MAX, m_qp);<br>
+ m_qp = x265_clip3(m_param->rc.qpMin, m_param->rc.qpMax, m_qp);<br>
rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq = m_qp;<br>
if (m_isAbr || m_2pass)<br>
{<br>
@@ -1647,6 +1659,8 @@<br>
double abrBuffer = 2 * m_rateTolerance * m_bitrate;<br>
if (m_2pass)<br>
{<br>
+ double lmin = m_lmin[m_sliceType];<br>
+ double lmax = m_lmax[m_sliceType];<br>
int64_t diff;<br>
if (!m_isVbv)<br>
{<br>
@@ -1697,17 +1711,17 @@<br>
double sizeConstraint = 1 + expectedFullness;<br>
qmax = X265_MAX(qmax, rce->newQScale);<br>
if (expectedFullness < .05)<br>
- qmax = MAX_MAX_QPSCALE;<br>
- qmax = X265_MIN(qmax, MAX_MAX_QPSCALE);<br>
+ qmax = lmax;<br>
+ qmax = X265_MIN(qmax, lmax);<br>
while (((expectedVbv < rce->expectedVbv/sizeConstraint) && (q < qmax)) ||<br>
- ((expectedVbv < 0) && (q < MAX_MAX_QPSCALE)))<br>
+ ((expectedVbv < 0) && (q < lmax)))<br>
{<br>
q *= 1.05;<br>
expectedSize = qScale2bits(rce, q);<br>
expectedVbv = m_bufferFill + m_bufferRate - expectedSize;<br>
}<br>
}<br>
- q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);<br>
+ q = x265_clip3(lmin, lmax, q);<br>
}<br>
else<br>
{<br>
@@ -1724,7 +1738,8 @@<br>
* tolerances, the bit distribution approaches that of 2pass. */<br>
<br>
double overflow = 1;<br>
- double lqmin = MIN_QPSCALE, lqmax = MAX_MAX_QPSCALE;<br>
+ double lqmin = m_lmin[m_sliceType];<br>
+ double lqmax = m_lmax[m_sliceType];<br>
m_shortTermCplxSum *= 0.5;<br>
m_shortTermCplxCount *= 0.5;<br>
m_shortTermCplxSum += m_currentSatd / (CLIP_DURATION(m_frameDuration) / BASE_FRAME_DURATION);<br>
@@ -1810,7 +1825,7 @@<br>
x265_qp2qScale(ABR_INIT_QP_MAX);<br>
q = X265_MIN(lqmax, q);<br>
}<br>
- q = x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);<br>
+ q = x265_clip3(lqmin, lqmax, q);<br>
/* Set a min qp at scenechanges and transitions */<br>
if (m_isSceneTransition)<br>
{<br>
@@ -1974,6 +1989,8 @@<br>
{<br>
// B-frames are not directly subject to VBV,<br>
// since they are controlled by referenced P-frames' QPs.<br>
+ double lmin = m_lmin[m_sliceType];<br>
+ double lmax = m_lmax[m_sliceType];<br>
double q0 = q;<br>
if (m_isVbv && m_currentSatd > 0 && curFrame)<br>
{<br>
@@ -2087,20 +2104,20 @@<br>
if (m_rateFactorMaxIncrement)<br>
{<br>
double qpNoVbv = x265_qScale2qp(q0);<br>
- double qmax = X265_MIN(MAX_MAX_QPSCALE,x265_qp2qScale(qpNoVbv + m_rateFactorMaxIncrement));<br>
- return x265_clip3(MIN_QPSCALE, qmax, q);<br>
+ double qmax = X265_MIN(lmax,x265_qp2qScale(qpNoVbv + m_rateFactorMaxIncrement));<br>
+ return x265_clip3(lmin, qmax, q);<br>
}<br>
}<br>
if (m_2pass)<br>
{<br>
- double min = log(MIN_QPSCALE);<br>
- double max = log(MAX_MAX_QPSCALE);<br>
+ double min = log(lmin);<br>
+ double max = log(lmax);<br>
q = (log(q) - min) / (max - min) - 0.5;<br>
q = 1.0 / (1.0 + exp(-4 * q));<br>
q = q*(max - min) + min;<br>
return exp(q);<br>
}<br>
- return x265_clip3(MIN_QPSCALE, MAX_MAX_QPSCALE, q);<br>
+ return x265_clip3(lmin, lmax, q);<br>
}<br>
<br>
double RateControl::predictRowsSizeSum(Frame* curFrame, RateControlEntry* rce, double qpVbv, int32_t& encodedBitsSoFar)<br>
@@ -2215,8 +2232,8 @@<br>
int canReencodeRow = 1;<br>
/* tweak quality based on difference from predicted size */<br>
double prevRowQp = qpVbv;<br>
- double qpAbsoluteMax = QP_MAX_MAX;<br>
- double qpAbsoluteMin = QP_MIN;<br>
+ double qpAbsoluteMax = m_param->rc.qpMax;<br>
+ double qpAbsoluteMin = m_param->rc.qpMin;<br>
if (m_rateFactorMaxIncrement)<br>
qpAbsoluteMax = X265_MIN(qpAbsoluteMax, rce->qpNoVbv + m_rateFactorMaxIncrement);<br>
<br>
@@ -2435,7 +2452,7 @@<br>
avgQpRc += curEncData.m_rowStat[i].sumQpRc;<br>
<br>
avgQpRc /= slice->m_sps->numCUsInFrame;<br>
- curEncData.m_avgQpRc = x265_clip3((double)QP_MIN, (double)QP_MAX_MAX, avgQpRc);<br>
+ curEncData.m_avgQpRc = x265_clip3((double)m_param->rc.qpMin, (double)m_param->rc.qpMax, avgQpRc);<br>
rce->qpaRc = curEncData.m_avgQpRc;<br>
}<br>
<br>
diff -r 43ca544799c2 -r 98a948623fdc source/encoder/ratecontrol.h<br>
--- a/source/encoder/ratecontrol.h Fri Jul 15 12:43:23 2016 +0530<br>
+++ b/source/encoder/ratecontrol.h Fri Jul 15 16:44:41 2016 +0530<br>
@@ -162,6 +162,8 @@<br>
double m_accumPNorm;<br>
double m_lastQScaleFor[3]; /* last qscale for a specific pict type, used for max_diff & ipb factor stuff */<br>
double m_lstep;<br>
+ double m_lmin[3];<br>
+ double m_lmax[3];<br>
double m_shortTermCplxSum;<br>
double m_shortTermCplxCount;<br>
double m_lastRceq;<br>
diff -r 43ca544799c2 -r 98a948623fdc source/encoder/sao.cpp<br>
--- a/source/encoder/sao.cpp Fri Jul 15 12:43:23 2016 +0530<br>
+++ b/source/encoder/sao.cpp Fri Jul 15 16:44:41 2016 +0530<br>
@@ -1197,7 +1197,7 @@<br>
<br>
int qpCb = qp;<br>
if (m_param->internalCsp == X265_CSP_I420)<br>
- qpCb = x265_clip3(QP_MIN, QP_MAX_MAX, (int)g_chromaScale[qp + slice->m_pps->chromaQpOffset[0]]);<br>
+ qpCb = x265_clip3(m_param->rc.qpMin, m_param->rc.qpMax, (int)g_chromaScale[qp + slice->m_pps->chromaQpOffset[0]]);<br>
else<br>
qpCb = X265_MIN(qp + slice->m_pps->chromaQpOffset[0], QP_MAX_SPEC);<br>
<br>
diff -r 43ca544799c2 -r 98a948623fdc source/x265.h<br>
--- a/source/x265.h Fri Jul 15 12:43:23 2016 +0530<br>
+++ b/source/x265.h Fri Jul 15 16:44:41 2016 +0530<br>
@@ -1161,6 +1161,12 @@<br>
<br>
/* internally enable if tune grain is set */<br>
int bEnableGrain;<br>
+<br>
+ /* sets a hard upper limit on QP */<br>
+ int qpMax;<br>
+<br>
+ /* sets a hard lower limit on QP */<br>
+ int qpMin;<br>
} rc;<br>
<br>
/*== Video Usability Information ==*/<br>
diff -r 43ca544799c2 -r 98a948623fdc source/x265cli.h<br>
--- a/source/x265cli.h Fri Jul 15 12:43:23 2016 +0530<br>
+++ b/source/x265cli.h Fri Jul 15 16:44:41 2016 +0530<br>
@@ -152,6 +152,8 @@<br>
{ "pbratio", required_argument, NULL, 0 },<br>
{ "qcomp", required_argument, NULL, 0 },<br>
{ "qpstep", required_argument, NULL, 0 },<br>
+ { "qpmin", required_argument, NULL, 0 },<br>
+ { "qpmax", required_argument, NULL, 0 },<br>
{ "ratetol", required_argument, NULL, 0 },<br>
{ "cplxblur", required_argument, NULL, 0 },<br>
{ "qblur", required_argument, NULL, 0 },<br>
@@ -388,6 +390,8 @@<br>
H1(" --pbratio <float> QP factor between P and B. Default %.2f\n", param->rc.pbFactor);<br>
H1(" --qcomp <float> Weight given to predicted complexity. Default %.2f\n", param->rc.qCompress);<br>
H1(" --qpstep <integer> The maximum single adjustment in QP allowed to rate control. Default %d\n", param->rc.qpStep);<br>
+ H1(" --qpmin <integer> sets a hard lower limit on QP allowed to ratecontrol. Default %d\n", param->rc.qpMin);<br>
+ H1(" --qpmax <integer> sets a hard upper limit on QP allowed to ratecontrol. Default %d\n", param->rc.qpMax);<br>
H1(" --cbqpoffs <integer> Chroma Cb QP Offset [-12..12]. Default %d\n", param->cbQpOffset);<br>
H1(" --crqpoffs <integer> Chroma Cr QP Offset [-12..12]. Default %d\n", param->crQpOffset);<br>
H1(" --scaling-list <string> Specify a file containing HM style quant scaling lists or 'default' or 'off'. Default: off\n");<br>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div>Deepthi Nandakumar<br></div>Engineering Manager, x265<br></div>Multicoreware, Inc<br></div></div>
</div></div>