<p dir="ltr">LGTM</p>
<div class="gmail_quote">On Nov 6, 2015 1:41 PM, "Ximing Cheng" <<a href="mailto:chengximing1989@foxmail.com">chengximing1989@foxmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Ximing Cheng <<a href="mailto:ximingcheng@tencent.com">ximingcheng@tencent.com</a>><br>
# Date 1446797063 -28800<br>
# Fri Nov 06 16:04:23 2015 +0800<br>
# Node ID f11b17b4656a85a15dc82fd04485fbf920848e4d<br>
# Parent 45ea73c63c12c66e5e5e777e80853c8b3cadf101<br>
rc: improve loop in clipQscale<br>
<br>
diff -r 45ea73c63c12 -r f11b17b4656a source/encoder/ratecontrol.cpp<br>
--- a/source/encoder/ratecontrol.cpp Fri Nov 06 11:55:27 2015 +0530<br>
+++ b/source/encoder/ratecontrol.cpp Fri Nov 06 16:04:23 2015 +0800<br>
@@ -1756,6 +1756,7 @@<br>
* is in a reasonable state by the end of the lookahead. */<br>
int loopTerminate = 0;<br>
/* Avoid an infinite loop. */<br>
+ double pSliceFactor = m_sliceType == I_SLICE ? m_param->rc.ipFactor : (m_sliceType == B_SLICE ? 1 / m_param->rc.pbFactor : 1);<br>
for (int iterations = 0; iterations < 1000 && loopTerminate != 3; iterations++)<br>
{<br>
double frameQ[3];<br>
@@ -1764,7 +1765,7 @@<br>
double bufferFillCur = m_bufferFill - curBits;<br>
double targetFill;<br>
double totalDuration = m_frameDuration;<br>
- frameQ[P_SLICE] = m_sliceType == I_SLICE ? q * m_param->rc.ipFactor : (m_sliceType == B_SLICE ? q / m_param->rc.pbFactor : q);<br>
+ frameQ[P_SLICE] = q * pSliceFactor;<br>
frameQ[B_SLICE] = frameQ[P_SLICE] * m_param->rc.pbFactor;<br>
frameQ[I_SLICE] = frameQ[P_SLICE] / m_param->rc.ipFactor;<br>
/* Loop over the planned future frames. */<br>
@@ -1798,12 +1799,15 @@<br>
continue;<br>
}<br>
/* Try to get the buffer not more than 80% filled, but don't set an impossible goal. */<br>
- targetFill = x265_clip3(m_bufferSize * (1 - 0.2 * finalDur), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);<br>
- if (m_isCbr && bufferFillCur > targetFill && !m_isSceneTransition)<br>
+ if (m_isCbr && !m_isSceneTransition)<br>
{<br>
- q /= 1.01;<br>
- loopTerminate |= 2;<br>
- continue;<br>
+ targetFill = x265_clip3(m_bufferSize * (1 - 0.2 * finalDur), m_bufferSize, m_bufferFill - totalDuration * m_vbvMaxRate * 0.5);<br>
+ if (bufferFillCur > targetFill)<br>
+ {<br>
+ q /= 1.01;<br>
+ loopTerminate |= 2;<br>
+ continue;<br>
+ }<br>
}<br>
break;<br>
}<br>
@@ -1857,7 +1861,7 @@<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>
+ double qmax = X265_MIN(MAX_MAX_QPSCALE, x265_qp2qScale(qpNoVbv + m_rateFactorMaxIncrement));<br>
return x265_clip3(MIN_QPSCALE, qmax, q);<br>
}<br>
}<br>
<br>
<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>