[x265] [PATCH 2 of 6] vbv: enable vbvLookahead for Keyframes; accumulate frame rowSatds from lowres rowSatds

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Thu Feb 20 14:25:44 CET 2014


# HG changeset patch
# User Aarthi Thirumalai
# Date 1392896018 -19800
#      Thu Feb 20 17:03:38 2014 +0530
# Node ID 1c037c64274dce2f39db348967259d7d623c1b18
# Parent  39efc006d3efa89df765b3d62e810854b41fe401
vbv: enable vbvLookahead for Keyframes; accumulate frame rowSatds from lowres rowSatds.

diff -r 39efc006d3ef -r 1c037c64274d source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Thu Feb 20 16:53:37 2014 +0530
+++ b/source/encoder/slicetype.cpp	Thu Feb 20 17:03:38 2014 +0530
@@ -173,11 +173,39 @@
     }
 
     if (cfg->param.rc.cuTree)
+    {
         pic->m_lowres.satdCost = frameCostRecalculate(frames, p0, p1, b);
+        if (b && cfg->param.rc.vbvBufferSize)
+            frameCostRecalculate(frames,b, b, b);
+    }
+
     else if (cfg->param.rc.aqMode)
         pic->m_lowres.satdCost = pic->m_lowres.costEstAq[b - p0][p1 - b];
     else
         pic->m_lowres.satdCost = pic->m_lowres.costEst[b - p0][p1 - b];
+
+    if (cfg->param.rc.vbvBufferSize > 0 && cfg->param.rc.vbvMaxBitrate > 0)
+    {
+        pic->m_lowres.lowresCostForRc = pic->m_lowres.lowresCosts[b - p0][p1 - b];
+        uint32_t lowresRow = 0 , lowresCol = 0, lowresCuIdx = 0, sum = 0;
+        uint32_t scale = cfg->param.maxCUSize / (2 * X265_LOWRES_CU_SIZE);
+        uint32_t widthInLowresCu = (uint32_t)widthInCU, heightInLowresCu = (uint32_t)heightInCU;
+
+        for (uint32_t row = 0; row < pic->getFrameHeightInCU(); row++)
+        {
+            lowresRow = row * scale;
+            for (uint32_t cnt = 0 ; cnt < scale && lowresRow < heightInLowresCu; lowresRow++, cnt++)
+            {
+                sum = 0;
+                lowresCuIdx = lowresRow * widthInLowresCu ;
+                for (lowresCol = 0; lowresCol < widthInLowresCu; lowresCol++, lowresCuIdx++)
+                {
+                    sum +=  pic->m_lowres.lowresCostForRc[lowresCuIdx];
+                }
+                pic->m_rowSatdForVbv[row] += sum;
+            }
+          }
+      }
     return pic->m_lowres.satdCost;
 }
 
@@ -186,6 +214,7 @@
     Lowres *frames[X265_LOOKAHEAD_MAX];
     TComPic *list[X265_LOOKAHEAD_MAX];
     TComPic *ipic = inputQueue.first();
+    bool isKeyFrameAnalyse = (cfg->param.rc.cuTree || (cfg->param.rc.vbvBufferSize && cfg->param.lookaheadDepth));
 
     if (!est.rows && ipic)
         est.init(cfg, ipic);
@@ -371,6 +400,10 @@
             outputQueue.pushBack(*list[i]);
         }
     }
+    if (isKeyFrameAnalyse && IS_X265_TYPE_I(lastNonB->sliceType))
+    {
+        slicetypeAnalyse(frames,true);
+    }
 }
 
 void Lookahead::vbvLookahead(Lowres **frames, int numFrames, int keyframe)


More information about the x265-devel mailing list