<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 8, 2014 at 10:39 AM, <span dir="ltr"><<a href="mailto:gopu@multicorewareinc.com" target="_blank">gopu@multicorewareinc.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"># HG changeset patch<br>
# User Gopu Govindaswamy<br>
# Date 1399524053 -19800<br>
# Thu May 08 10:10:53 2014 +0530<br>
# Node ID 7a3657ff29e24b7832002b76b3f9096736d20a36<br>
# Parent 6494bb2e64253fc0f9413b88933634d1f37c4881<br>
x265: implemented crf-min that specifies a minimum rate factor value for encode<br>
<br>
diff -r 6494bb2e6425 -r 7a3657ff29e2 source/common/param.cpp<br>
--- a/source/common/param.cpp Wed May 07 14:03:25 2014 -0500<br>
+++ b/source/common/param.cpp Thu May 08 10:10:53 2014 +0530<br>
@@ -604,6 +604,7 @@<br>
OPT("vbv-bufsize") p->rc.vbvBufferSize = atoi(value);<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 = atoi(value);<br>
OPT("crf")<br>
{<br>
p->rc.rfConstant = atof(value);<br>
diff -r 6494bb2e6425 -r 7a3657ff29e2 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Wed May 07 14:03:25 2014 -0500<br>
+++ b/source/encoder/encoder.cpp Thu May 08 10:10:53 2014 +0530<br>
@@ -1342,6 +1342,12 @@<br>
x265_log(p, X265_LOG_WARNING, "Support for interlaced video is experimental\n");<br>
}<br>
<br>
+ if (p->rc.rfConstantMin > p->rc.rfConstant)<br>
+ {<br>
+ x265_log(param, X265_LOG_WARNING, "CRF min must be less than CRF\n");<br>
+ p->rc.rfConstantMin = 0;<br>
+ }<br>
+<br>
m_bframeDelay = p->bframes ? (p->bBPyramid ? 2 : 1) : 0;<br>
<br>
//====== Coding Tools ========<br>
diff -r 6494bb2e6425 -r 7a3657ff29e2 source/encoder/ratecontrol.cpp<br>
--- a/source/encoder/ratecontrol.cpp Wed May 07 14:03:25 2014 -0500<br>
+++ b/source/encoder/ratecontrol.cpp Thu May 08 10:10:53 2014 +0530<br>
@@ -207,6 +207,7 @@<br>
param->rc.rfConstant = Clip3((double)-QP_BD_OFFSET, (double)51, param->rc.rfConstant);<br>
param->rc.rfConstantMax = Clip3((double)-QP_BD_OFFSET, (double)51, param->rc.rfConstantMax);<br>
rateFactorMaxIncrement = 0;<br>
+ rateFactorMaxDecrement = 0;<br>
<br>
if (param->rc.rateControlMode == X265_RC_CRF)<br>
{<br>
@@ -226,6 +227,8 @@<br>
rateFactorMaxIncrement = 0;<br>
}<br>
}<br>
+ if (param->rc.rfConstantMin)<br>
+ rateFactorMaxDecrement = param->rc.rfConstant - param->rc.rfConstantMin;<br>
}<br>
<br>
isAbr = param->rc.rateControlMode != X265_RC_CQP; // later add 2pass option<br>
@@ -851,10 +854,15 @@<br>
/* tweak quality based on difference from predicted size */<br>
double prevRowQp = qpVbv;<br>
double qpAbsoluteMax = MAX_MAX_QP;<br>
+ double qpAbsoluteMin = MIN_QP;<br>
if (rateFactorMaxIncrement)<br>
qpAbsoluteMax = X265_MIN(qpAbsoluteMax, rce->qpNoVbv + rateFactorMaxIncrement);<br>
+<br>
+ if (rateFactorMaxDecrement)<br>
+ qpAbsoluteMin = X265_MAX(qpAbsoluteMin, rce->qpNoVbv - rateFactorMaxIncrement);<br>
+<br></blockquote><div>should not the above line be maximum of qpAbsoluteMin and qpNoVbv - rateFactorMaxDecrement? </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
double qpMax = X265_MIN(prevRowQp + param->rc.qpStep, qpAbsoluteMax);<br>
- double qpMin = X265_MAX(prevRowQp - param->rc.qpStep, MIN_QP);<br>
+ double qpMin = X265_MAX(prevRowQp - param->rc.qpStep, qpAbsoluteMin);<br>
double stepSize = 0.5;<br>
double bufferLeftPlanned = rce->bufferFill - rce->frameSizePlanned;<br>
<br>
@@ -922,6 +930,12 @@<br>
qpVbv = Clip3(prevRowQp + 1.0f, qpMax, (prevRowQp + qpVbv) * 0.5);<br>
return -1;<br>
}<br>
+<br>
+ if (qpVbv < qpMin && prevRowQp > qpMin && canReencodeRow)<br>
+ {<br>
+ qpVbv = Clip3(prevRowQp + 1.0f, (prevRowQp + qpVbv) * 0.5, qpMin);<br>
+ return -1;<br>
+ }<br></blockquote><div>i think the above condition needs to be executed only when param->rc.rfConstantMin is set. else we dont need to reencode if qp falls lesser in normal scenarios. </div><div>also, the clip should be done as Clip3(qpMin, (prevRowQp - qpVbv) * 0.5, prevRowQp - 1.0f); - find a value between qpMin and prevRowQp. </div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
}<br>
else<br>
{<br>
diff -r 6494bb2e6425 -r 7a3657ff29e2 source/encoder/ratecontrol.h<br>
--- a/source/encoder/ratecontrol.h Wed May 07 14:03:25 2014 -0500<br>
+++ b/source/encoder/ratecontrol.h Thu May 08 10:10:53 2014 +0530<br>
@@ -96,6 +96,7 @@<br>
double vbvMinRate; /* in kbps */<br>
bool singleFrameVbv;<br>
double rateFactorMaxIncrement; /* Don't allow RF above (CRF + this value). */<br>
+ double rateFactorMaxDecrement; /* don't allow RF below (this value). */<br>
bool isVbv;<br>
Predictor pred[5];<br>
Predictor predBfromP;<br>
diff -r 6494bb2e6425 -r 7a3657ff29e2 source/x265.cpp<br>
--- a/source/x265.cpp Wed May 07 14:03:25 2014 -0500<br>
+++ b/source/x265.cpp Thu May 08 10:10:53 2014 +0530<br>
@@ -129,6 +129,7 @@<br>
{ "weightb", no_argument, NULL, 0 },<br>
{ "crf", required_argument, NULL, 0 },<br>
{ "crf-max", required_argument, NULL, 0 },<br>
+ { "crf-min", required_argument, NULL, 0 },<br>
{ "vbv-maxrate", required_argument, NULL, 0 },<br>
{ "vbv-bufsize", required_argument, NULL, 0 },<br>
{ "vbv-init", required_argument, NULL, 0 },<br>
@@ -360,6 +361,8 @@<br>
H0(" --crf <float> Quality-based VBR (0-51). Default %f\n", param->rc.rfConstant);<br>
H0(" --crf-max <float> With CRF+VBV, limit RF to this value. 0 for no limit (default)\n");<br>
H0(" May cause VBV underflows!\n");<br>
+ H0(" --crf-min <float> With CRF+VBV, limit RF to this value. 0 for no limit (default)\n");<br>
+ H0(" this specifies a minimum rate factor value for encode!\n");<br>
H0(" --vbv-maxrate <integer> Max local bitrate (kbit/s). Default %d\n", param->rc.vbvMaxBitrate);<br>
H0(" --vbv-bufsize <integer> Set size of the VBV buffer (kbit). Default %d\n", param->rc.vbvBufferSize);<br>
H0(" --vbv-init <float> Initial VBV buffer occupancy (fraction of bufsize or in kbits). Default %f\n", param->rc.vbvBufferInit);<br>
diff -r 6494bb2e6425 -r 7a3657ff29e2 source/x265.h<br>
--- a/source/x265.h Wed May 07 14:03:25 2014 -0500<br>
+++ b/source/x265.h Thu May 08 10:10:53 2014 +0530<br>
@@ -703,6 +703,9 @@<br>
<br>
/* In CRF mode, maximum CRF as caused by VBV. 0 implies no limit */<br>
double rfConstantMax;<br>
+<br>
+ /* In CRF mode, minimum CRF as caused by VBV */<br>
+ double rfConstantMin;<br>
} rc;<br>
<br>
/*== Video Usability Information ==*/<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" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div><br></div></div>