<div dir="ltr">pls ignore.. sending revised patch for this </div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 10, 2015 at 10:48 PM, Aarthi Priya Thirumalai <span dir="ltr"><<a href="mailto:aarthi@multicorewareinc.com" target="_blank">aarthi@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 Aarthi Priya Thirumalai <<a href="mailto:aarthi@multicorewareinc.com">aarthi@multicorewareinc.com</a>><br>
# Date 1449763621 -19800<br>
# Thu Dec 10 21:37:01 2015 +0530<br>
# Node ID 721d60a7988b85083f72832b58e5e98f42d5a678<br>
# Parent 33d04da2f68830ac51151cfbda8f38fb9a7e8bb9<br>
rc: fix rate factor values recorded in csv<br>
<br>
diff -r 33d04da2f688 -r 721d60a7988b source/encoder/ratecontrol.cpp<br>
--- a/source/encoder/ratecontrol.cpp Wed Dec 09 22:24:25 2015 +0530<br>
+++ b/source/encoder/ratecontrol.cpp Thu Dec 10 21:37:01 2015 +0530<br>
@@ -142,6 +142,7 @@<br>
rce->expectedVbv = rce2Pass->expectedVbv;<br>
rce->blurredComplexity = rce2Pass->blurredComplexity;<br>
rce->sliceType = rce2Pass->sliceType;<br>
+ rce->qRceq = rce2Pass->qRceq;<br>
}<br>
<br>
} // end anonymous namespace<br>
@@ -509,7 +510,7 @@<br>
char picType;<br>
int e;<br>
char *next;<br>
- double qpRc, qpAq, qNoVbv;<br>
+ double qpRc, qpAq, qNoVbv, qRceq;<br>
next = strstr(p, ";");<br>
if (next)<br>
*next++ = 0;<br>
@@ -520,8 +521,8 @@<br>
return false;<br>
}<br>
rce = &m_rce2Pass[frameNumber];<br>
- e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf q-noVbv:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",<br>
- &picType, &qpRc, &qpAq, &qNoVbv, &rce->coeffBits,<br>
+ e += sscanf(p, " in:%*d out:%*d type:%c q:%lf q-aq:%lf q-noVbv:%lf q-Rceq:%lf tex:%d mv:%d misc:%d icu:%lf pcu:%lf scu:%lf",<br>
+ &picType, &qpRc, &qpAq, &qNoVbv, &qRceq, &rce->coeffBits,<br>
&rce->mvBits, &rce->miscBits, &rce->iCuCount, &rce->pCuCount,<br>
&rce->skipCuCount);<br>
rce->keptAsRef = true;<br>
@@ -545,6 +546,7 @@<br>
rce->qpNoVbv = qNoVbv;<br>
rce->qpaRc = qpRc;<br>
rce->qpAq = qpAq;<br>
+ rce->qRceq = qRceq;<br>
p = next;<br>
}<br>
X265_FREE(statsBuf);<br>
@@ -2239,20 +2241,32 @@<br>
{<br>
if (m_param->rc.rateControlMode == X265_RC_ABR && !m_param->rc.bStatRead)<br>
checkAndResetABR(rce, true);<br>
+ }<br>
+ if (m_param->rc.rateControlMode == X265_RC_CRF)<br>
+ {<br>
+ double crfVal;<br>
+ if (m_2pass || abs(curEncData.m_avgQpRc - rce->qpNoVbv) > 0.5)<br>
+ {<br>
+ double qpRef = curEncData.m_avgQpRc;<br>
+ if (m_2pass)<br>
+ {<br>
+ double qpPrev = x265_qScale2qp(rce->qScale);<br>
+ qpRef = abs(curEncData.m_avgQpRc - qpPrev) > 0.1 ? curEncData.m_avgQpRc : qpPrev;<br>
+ }<br>
+ double crfFactor = rce->qRceq /x265_qp2qScale(qpRef);<br>
+ if(rce->sliceType == I_SLICE)<br>
+ crfFactor /= m_param->rc.ipFactor;<br>
+ else if (rce->sliceType == B_SLICE)<br>
+ crfFactor *= m_param->rc.pbFactor;<br>
+ double baseCplx = m_ncu * (m_param->bframes ? 120 : 80);<br>
+ double mbtree_offset = m_param->rc.cuTree ? (1.0 - m_param->rc.qCompress) * 13.5 : 0;<br>
+ crfVal = x265_qScale2qp(pow(baseCplx, 1 - m_qCompress) / crfFactor) - mbtree_offset;<br>
+ }<br>
+ else<br>
+ crfVal = rce->sliceType == I_SLICE ? m_param->rc.rfConstant - m_ipOffset :<br>
+ (rce->sliceType == B_SLICE ? m_param->rc.rfConstant + m_pbOffset : m_param->rc.rfConstant);<br>
<br>
- if (m_param->rc.rateControlMode == X265_RC_CRF)<br>
- {<br>
- if (int(curEncData.m_avgQpRc + 0.5) == slice->m_sliceQp)<br>
- curEncData.m_rateFactor = m_rateFactorConstant;<br>
- else<br>
- {<br>
- /* If vbv changed the frame QP recalculate the rate-factor */<br>
- double baseCplx = m_ncu * (m_param->bframes ? 120 : 80);<br>
- double mbtree_offset = m_param->rc.cuTree ? (1.0 - m_param->rc.qCompress) * 13.5 : 0;<br>
- curEncData.m_rateFactor = pow(baseCplx, 1 - m_qCompress) /<br>
- x265_qp2qScale(int(curEncData.m_avgQpRc + 0.5) + mbtree_offset);<br>
- }<br>
- }<br>
+ curEncData.m_rateFactor = crfVal;<br>
}<br>
<br>
if (m_isAbr && !m_isAbrReset)<br>
@@ -2346,10 +2360,10 @@<br>
: rce->sliceType == P_SLICE ? 'P'<br>
: IS_REFERENCED(curFrame) ? 'B' : 'b';<br>
if (fprintf(m_statFileOut,<br>
- "in:%d out:%d type:%c q:%.2f q-aq:%.2f q-noVbv:%.2f tex:%d mv:%d misc:%d icu:%.2f pcu:%.2f scu:%.2f ;\n",<br>
+ "in:%d out:%d type:%c q:%.2f q-aq:%.2f q-noVbv:%.2f q-Rceq:%.2f tex:%d mv:%d misc:%d icu:%.2f pcu:%.2f scu:%.2f ;\n",<br>
rce->poc, rce->encodeOrder,<br>
cType, curEncData.m_avgQpRc, curEncData.m_avgQpAq,<br>
- rce->qpNoVbv,<br>
+ rce->qpNoVbv, rce->qRceq,<br>
curFrame->m_encData->m_frameStats.coeffBits,<br>
curFrame->m_encData->m_frameStats.mvBits,<br>
curFrame->m_encData->m_frameStats.miscBits,<br>
</blockquote></div><br></div>