[x265] [PATCH 2 of 3] rc: don't update predictors from previous frames, after reset at scenecut

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Tue Sep 22 11:50:57 CEST 2015


# HG changeset patch
# User Aarthi Thirumalai
# Date 1442909407 -19800
#      Tue Sep 22 13:40:07 2015 +0530
# Node ID 5a3c92b92a049f49e7712ad3d2ba458937e0c55d
# Parent  819f8cf72d15c6a3dba77383881b8f4c1140542c
rc: don't update predictors from previous frames, after reset at scenecut.

diff -r 819f8cf72d15 -r 5a3c92b92a04 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Tue Sep 22 13:33:13 2015 +0530
+++ b/source/encoder/ratecontrol.cpp	Tue Sep 22 13:40:07 2015 +0530
@@ -182,6 +182,7 @@
     m_finalFrameCount = 0;
     m_numEntries = 0;
     m_isSceneTransition = false;
+    m_lastPredictorReset = 0;
     if (m_param->rc.rateControlMode == X265_RC_CRF)
     {
         m_param->rc.qp = (int)m_param->rc.rfConstant;
@@ -961,10 +962,11 @@
         copyRceData(rce, &m_rce2Pass[rce->poc]);
     }
     rce->isActive = true;
-    bool isframeAfterKeyframe = m_sliceType != I_SLICE && m_curSlice->m_refFrameList[0][0]->m_encData->m_slice->m_sliceType == I_SLICE;
+    bool isRefFrameScenecut = m_sliceType!= I_SLICE && m_curSlice->m_refFrameList[0][0]->m_lowres.bScenecut == 1;
     if (curFrame->m_lowres.bScenecut)
     {
         m_isSceneTransition = true;
+        m_lastPredictorReset = rce->encodeOrder;
         /* Frame Predictors and Row predictors used in vbv */
         for (int i = 0; i < 4; i++)
         {
@@ -974,10 +976,20 @@
             m_pred[i].offset = 0.0;
         }
         m_pred[0].coeff = m_pred[3].coeff = 0.75;
+        if (m_param->rc.qCompress >= 0.8) // when tuned for grain 
+        {
+            m_pred[1].coeff = 0.75;
+            m_pred[0].coeff = m_pred[3].coeff = 0.50;
+        }
     }
-    else if (m_sliceType != B_SLICE && !isframeAfterKeyframe)
+    else if (m_sliceType != B_SLICE && !isRefFrameScenecut)
         m_isSceneTransition = false;
 
+    if (rce->encodeOrder < m_lastPredictorReset + m_param->frameNumThreads)
+    {
+        rce->rowPreds[0][0].count = 0;
+    }
+
     rce->bLastMiniGopBFrame = curFrame->m_lowres.bLastMiniGopBFrame;
     rce->bufferRate = m_bufferRate;
     rce->rowCplxrSum = 0.0;
@@ -2149,7 +2161,7 @@
 {
     int predType = rce->sliceType;
     predType = rce->sliceType == B_SLICE && rce->keptAsRef ? 3 : predType;
-    if (rce->lastSatd >= m_ncu)
+    if (rce->lastSatd >= m_ncu && rce->encodeOrder >= m_lastPredictorReset)
         updatePredictor(&m_pred[predType], x265_qp2qScale(rce->qpaRc), (double)rce->lastSatd, (double)bits);
     if (!m_isVbv)
         return;
@@ -2205,6 +2217,7 @@
         }
         else
             curEncData.m_avgQpAq = curEncData.m_avgQpRc;
+        rce->qpAq = curEncData.m_avgQpAq;
     }
 
     if (m_isAbr)
diff -r 819f8cf72d15 -r 5a3c92b92a04 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Tue Sep 22 13:33:13 2015 +0530
+++ b/source/encoder/ratecontrol.h	Tue Sep 22 13:40:07 2015 +0530
@@ -173,6 +173,7 @@
     int     m_numBframesInPattern;
     bool    m_isPatternPresent;
     bool    m_isSceneTransition;
+    int     m_lastPredictorReset;
 
     /* a common variable on which rateControlStart, rateControlEnd and rateControUpdateStats waits to
      * sync the calls to these functions. For example


More information about the x265-devel mailing list