[x265] [PATCH] Encoder statistics: Inter[% (2Nx2N %2NxN %Nx2N %AMP)] Intra[% (%DC %PLANAR %ANG)] Split[%] Skip[%]

kavitha at multicorewareinc.com kavitha at multicorewareinc.com
Mon Nov 18 07:10:32 CET 2013


# HG changeset patch
# User Kavitha Sampath <kavitha at multicorewareinc.com>
# Date 1384754526 -19800
#      Mon Nov 18 11:32:06 2013 +0530
# Node ID 96c180b4ed4f37b1af6a3d24de1d9419caac97eb
# Parent  e2895ce7bbeb2c3d845fee2578758d0012fa2cb4
Encoder statistics: Inter[% (2Nx2N %2NxN %Nx2N %AMP)] Intra[% (%DC %PLANAR %ANG)] Split[%] Skip[%]

diff -r e2895ce7bbeb -r 96c180b4ed4f source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp	Sun Nov 17 11:24:13 2013 -0600
+++ b/source/Lib/TLibEncoder/TEncCu.cpp	Mon Nov 18 11:32:06 2013 +0530
@@ -343,25 +343,13 @@
 
 /** \param  rpcCU pointer of CU data class
  */
-#if CU_STAT_LOGFILE
-extern int totalCU;
-extern int cntInter[4], cntIntra[4], cntSplit[4], cntIntraNxN;
-extern  int cuInterDistribution[4][4], cuIntraDistribution[4][3];
-extern  int cntSkipCu[4],  cntTotalCu[4];
-extern FILE* fp1;
 bool mergeFlag = 0;
-#endif
 
 void TEncCu::compressCU(TComDataCU* cu)
 {
     // initialize CU data
     m_bestCU[0]->initCU(cu->getPic(), cu->getAddr());
     m_tempCU[0]->initCU(cu->getPic(), cu->getAddr());
-#if CU_STAT_LOGFILE
-    totalCU++;
-    if (cu->getSlice()->getSliceType() != I_SLICE)
-        fprintf(fp1, "\n CU number : %d ", totalCU);
-#endif
 
     m_addSADDepth      = 0;
     m_LCUPredictionSAD = 0;
@@ -479,10 +467,8 @@
 {
     //PPAScopeEvent(TEncCu_xCompressIntraCU + depth);
 
-#if CU_STAT_LOGFILE
-    cntTotalCu[depth]++;
+    m_log->cntTotalCu[depth]++;
     int boundaryCu = 0;
-#endif
     m_abortFlag = false;
     TComPic* pic = outBestCU->getPic();
 
@@ -550,9 +536,7 @@
         // Early CU determination
         if (outBestCU->isSkipped(0))
         {
-#if CU_STAT_LOGFILE
-            cntSkipCu[depth]++;
-#endif
+            m_log->cntSkipCu[depth]++;
             bSubBranch = false;
         }
         else
@@ -609,9 +593,7 @@
             {
                 subBestPartCU[partUnitIdx]->copyToPic(nextDepth);
                 outTempCU->copyPartFrom(subBestPartCU[partUnitIdx], partUnitIdx, nextDepth);
-#if CU_STAT_LOGFILE
                 boundaryCu++;
-#endif
             }
         }
 
@@ -651,22 +633,18 @@
         }
 
         m_rdSbacCoders[nextDepth][CI_NEXT_BEST]->store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
-#if CU_STAT_LOGFILE
         if (outBestCU->m_totalCost < outTempCU->m_totalCost)
         {
-            cntIntra[depth]++;
-            cntIntra[depth + 1] = cntIntra[depth + 1] - 4 + boundaryCu;
+            m_log->cntIntra[depth]++;
+            m_log->cntIntra[depth + 1] = m_log->cntIntra[depth + 1] - 4 + boundaryCu;
         }
-#endif
         xCheckBestMode(outBestCU, outTempCU, depth); // RD compare current prediction with split prediction.
     }
 
-#if CU_STAT_LOGFILE
-    if (depth == 3 && bSubBranch)
+    if (depth == g_maxCUDepth - 1 && bSubBranch)
     {
-        cntIntra[depth]++;
+        m_log->cntIntra[depth]++;
     }
-#endif
     outBestCU->copyToPic(depth); // Copy Best data to Picture for next partition prediction.
 
     // Copy Yuv data to picture Yuv
@@ -685,9 +663,7 @@
 {
     //PPAScopeEvent(TEncCu_xCompressCU + depth);
 
-#if CU_STAT_LOGFILE
-    cntTotalCu[depth]++;
-#endif
+    m_log->cntTotalCu[depth]++;
     TComPic* pic = outBestCU->getPic();
     m_abortFlag = false;
 
@@ -738,15 +714,11 @@
                 xCheckRDCostInter(outBestCU, outTempCU, SIZE_2Nx2N);
                 outTempCU->initEstData(depth, qp); // by competition for inter_2Nx2N
             }
-#if CU_STAT_LOGFILE
             mergeFlag = 1;
-#endif
             // by Merge for inter_2Nx2N
             xCheckRDCostMerge2Nx2N(outBestCU, outTempCU, &earlyDetectionSkipMode, m_bestPredYuv[depth], m_bestRecoYuv[depth]);
 
-#if CU_STAT_LOGFILE
             mergeFlag = 0;
-#endif
             outTempCU->initEstData(depth, qp);
 
             if (!m_cfg->param.bEnableEarlySkip)
@@ -940,9 +912,7 @@
         // Early CU determination
         if (outBestCU->isSkipped(0))
         {
-#if CU_STAT_LOGFILE
-            cntSkipCu[depth]++;
-#endif
+            m_log->cntSkipCu[depth]++;
             bSubBranch = false;
         }
         else
@@ -1046,80 +1016,76 @@
         }
 
         m_rdSbacCoders[nextDepth][CI_NEXT_BEST]->store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
-#if  CU_STAT_LOGFILE
         if (outBestCU->m_totalCost < outTempCU->m_totalCost)
         {
             if (outBestCU->getPredictionMode(0) == MODE_INTER)
             {
-                cntInter[depth]++;
-                if (outBestCU->getPartitionSize(0) < 3)
+                m_log->cntInter[depth]++;
+                if (outBestCU->getPartitionSize(0) < AMP_ID)
                 {
-                    cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
+                    m_log->cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
                 }
                 else
                 {
-                    cuInterDistribution[depth][3]++;
+                    m_log->cuInterDistribution[depth][AMP_ID]++;
                 }
             }
             else if (outBestCU->getPredictionMode(0) == MODE_INTRA)
             {
-                cntIntra[depth]++;
+                m_log->cntIntra[depth]++;
                 if (outBestCU->getLumaIntraDir()[0] > 1)
                 {
-                    cuIntraDistribution[depth][2]++;
+                    m_log->cuIntraDistribution[depth][ANGULAR_MODE_ID]++;
                 }
                 else
                 {
-                    cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
+                    m_log->cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
                 }
             }
         }
         else
         {
-            cntSplit[depth]++;
+            m_log->cntSplit[depth]++;
         }
-#endif // if  LOGGING
         xCheckBestMode(outBestCU, outTempCU, depth); // RD compare current CU against split
     }
-#if CU_STAT_LOGFILE
-    if (depth == 3)
+    if (depth == g_maxCUDepth - 1)
     {
         if (!outBestCU->isSkipped(0))
         {
             if (outBestCU->getPredictionMode(0) == MODE_INTER)
             {
-                cntInter[depth]++;
-                if (outBestCU->getPartitionSize(0) < 3)
+                m_log->cntInter[depth]++;
+                if (outBestCU->getPartitionSize(0) < AMP_ID)
                 {
-                    cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
+                    m_log->cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
                 }
                 else
                 {
-                    cuInterDistribution[depth][3]++;
+                    m_log->cuInterDistribution[depth][AMP_ID]++;
                 }
             }
             else if (outBestCU->getPredictionMode(0) == MODE_INTRA)
             {
-                cntIntra[depth]++;
+                m_log->cntIntra[depth]++;
                 if (outBestCU->getPartitionSize(0) == SIZE_2Nx2N)
                 {
                     if (outBestCU->getLumaIntraDir()[0] > 1)
                     {
-                        cuIntraDistribution[depth][2]++;
+                        m_log->cuIntraDistribution[depth][ANGULAR_MODE_ID]++;
                     }
                     else
                     {
-                        cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
+                        m_log->cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
                     }
                 }
                 else if (outBestCU->getPartitionSize(0) == SIZE_NxN)
                 {
-                    cntIntraNxN++;
+                    m_log->cntIntraNxN++;
                 }
             }
         }
     }
-#endif // if LOGGING
     outBestCU->copyToPic(depth); // Copy Best data to Picture for next partition prediction.
     // Copy Yuv data to picture Yuv
     xCopyYuv2Pic(outBestCU->getPic(), outBestCU->getAddr(), outBestCU->getZorderIdxInCU(), depth, depth, outBestCU, lpelx, tpely);
diff -r e2895ce7bbeb -r 96c180b4ed4f source/Lib/TLibEncoder/TEncCu.h
--- a/source/Lib/TLibEncoder/TEncCu.h	Sun Nov 17 11:24:13 2013 -0600
+++ b/source/Lib/TLibEncoder/TEncCu.h	Mon Nov 18 11:32:06 2013 +0530
@@ -38,6 +38,11 @@
 #ifndef X265_TENCCU_H
 #define X265_TENCCU_H
 
+#define ANGULAR_MODE_ID 2
+#define AMP_ID 3
+#define INTER_MODES 4
+#define INTRA_MODES 3
+
 #include "TLibCommon/CommonDef.h"
 #include "TLibCommon/TComYuv.h"
 #include "TLibCommon/TComPrediction.h"
@@ -51,6 +56,22 @@
 
 //! \ingroup TLibEncoder
 //! \{
+struct StatisticLog
+{
+    uint64_t cntInter[4];
+    uint64_t cntIntra[4];
+    uint64_t cntSplit[4];
+    uint64_t cuInterDistribution[4][INTER_MODES];
+    uint64_t cuIntraDistribution[4][INTRA_MODES];
+    uint64_t cntIntraNxN;
+    uint64_t cntSkipCu[4];
+    uint64_t cntTotalCu[4];
+
+    StatisticLog()
+    {
+         memset(this, 0, sizeof(StatisticLog));
+    }
+};
 
 namespace x265 {
 // private namespace
@@ -111,6 +132,8 @@
 
 public:
 
+    StatisticLog  m_sliceTypeLog[3];
+    StatisticLog* m_log;
     TEncCu();
 
     void init(Encoder* top);
diff -r e2895ce7bbeb -r 96c180b4ed4f source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Sun Nov 17 11:24:13 2013 -0600
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Mon Nov 18 11:32:06 2013 +0530
@@ -46,11 +46,6 @@
 
 using namespace x265;
 
-#if CU_STAT_LOGFILE
-extern FILE *fp1;
-extern bool mergeFlag;
-UInt64      meCost;
-#endif
 DECLARE_CYCLE_COUNTER(ME);
 
 //! \ingroup TLibEncoder
@@ -2458,9 +2453,6 @@
 
                 mebits = bits[1];
             }
-#if CU_STAT_LOGFILE
-            meCost += listCost[0];
-#endif
         } // end if bTestNormalMC
 
         if (cu->getPartitionSize(partAddr) != SIZE_2Nx2N)
@@ -2509,9 +2501,6 @@
                 cu->setMVPNumSubParts(-1, REF_PIC_LIST_0, partAddr, partIdx, cu->getDepth(partAddr));
                 cu->setMVPIdxSubParts(-1, REF_PIC_LIST_1, partAddr, partIdx, cu->getDepth(partAddr));
                 cu->setMVPNumSubParts(-1, REF_PIC_LIST_1, partAddr, partIdx, cu->getDepth(partAddr));
-#if CU_STAT_LOGFILE
-                meCost += mrgCost;
-#endif
                 totalmebits += mrgBits;
             }
             else
@@ -2523,9 +2512,6 @@
                     cu->getCUMvField(REF_PIC_LIST_0)->setAllMvField(meMvField[0], partSize, partAddr, 0, partIdx);
                     cu->getCUMvField(REF_PIC_LIST_1)->setAllMvField(meMvField[1], partSize, partAddr, 0, partIdx);
                 }
-#if CU_STAT_LOGFILE
-                meCost += meCost;
-#endif
                 totalmebits += mebits;
             }
         }
diff -r e2895ce7bbeb -r 96c180b4ed4f source/common/common.h
--- a/source/common/common.h	Sun Nov 17 11:24:13 2013 -0600
+++ b/source/common/common.h	Mon Nov 18 11:32:06 2013 +0530
@@ -27,8 +27,6 @@
 #include <cstdlib>
 #include "x265.h"
 
-#define CU_STAT_LOGFILE 0
-
 #define X265_MIN(a, b) ((a) < (b) ? (a) : (b))
 #define X265_MAX(a, b) ((a) > (b) ? (a) : (b))
 #define COPY1_IF_LT(x, y) if ((y) < (x)) (x) = (y);
diff -r e2895ce7bbeb -r 96c180b4ed4f source/encoder/compress.cpp
--- a/source/encoder/compress.cpp	Sun Nov 17 11:24:13 2013 -0600
+++ b/source/encoder/compress.cpp	Mon Nov 18 11:32:06 2013 +0530
@@ -30,14 +30,6 @@
 
 using namespace x265;
 
-#if CU_STAT_LOGFILE
-extern int totalCU;
-extern int cntInter[4], cntIntra[4], cntSplit[4], cntIntraNxN;
-extern int cuInterDistribution[4][4], cuIntraDistribution[4][3];
-extern int cntSkipCu[4],  cntTotalCu[4];
-extern FILE* fp1;
-#endif
-
 void TEncCu::xEncodeIntraInInter(TComDataCU* cu, TComYuv* fencYuv, TComYuv* predYuv,  TShortYUV* outResiYuv, TComYuv* outReconYuv)
 {
     UInt64 puCost = 0;
@@ -357,9 +349,7 @@
 
 void TEncCu::xCompressInterCU(TComDataCU*& outBestCU, TComDataCU*& outTempCU, TComDataCU*& cu, uint32_t depth, uint32_t PartitionIndex)
 {
-#if CU_STAT_LOGFILE
-    cntTotalCu[depth]++;
-#endif
+    m_log->cntTotalCu[depth]++;
     m_abortFlag = false;
 
     TComPic* pic = outTempCU->getPic();
@@ -471,9 +461,6 @@
             m_search->estimateRDInterCU(outBestCU, m_origYuv[depth], m_bestPredYuv[depth], m_tmpResiYuv[depth],
                                         m_bestResiYuv[depth], m_bestRecoYuv[depth], false);
 
-#if CU_STAT_LOGFILE
-            fprintf(fp1, "\n N : %d ,  Best Inter : %d , ", outBestCU->getWidth(0) / 2, outBestCU->m_totalCost);
-#endif
 
             if (m_bestMergeCU[depth]->m_totalCost < outBestCU->m_totalCost)
             {
@@ -527,9 +514,7 @@
         /* Disable recursive analysis for whole CUs temporarily */
         if ((outBestCU != 0) && (outBestCU->isSkipped(0)))
         {
-#if CU_STAT_LOGFILE
-            cntSkipCu[depth]++;
-#endif
+            m_log->cntSkipCu[depth]++;
             bSubBranch = false;
         }
         else
@@ -547,14 +532,6 @@
         bBoundary = true;
         m_addSADDepth++;
     }
-#if CU_STAT_LOGFILE
-    if (outBestCU)
-    {
-        fprintf(fp1, "Inter 2Nx2N_Merge : %d , Intra : %d",  m_bestMergeCU[depth]->m_totalCost, m_intraInInterCU[depth]->m_totalCost);
-        if (outBestCU != m_bestMergeCU[depth] && outBestCU != m_intraInInterCU[depth])
-            fprintf(fp1, " , Best  Part Mode chosen :%d, Pred Mode : %d",  outBestCU->getPartitionSize(0), outBestCU->getPredictionMode(0));
-    }
-#endif
 
     // further split
     if (bSubBranch && bTrySplitDQP && depth < g_maxCUDepth - g_addCUDepth)
@@ -613,6 +590,7 @@
 
                 /* Copy Yuv data to picture Yuv */
                 xCopyYuv2Pic(outBestCU->getPic(), outBestCU->getAddr(), outBestCU->getZorderIdxInCU(), depth, depth, outBestCU, lpelx, tpely);
+                m_log->cntTotalCu[depth]--;
                 return;
             }
         }
@@ -697,47 +675,40 @@
 
         m_rdSbacCoders[nextDepth][CI_NEXT_BEST]->store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
 
-#if  CU_STAT_LOGFILE
         if (outBestCU != 0)
         {
             if (outBestCU->m_totalCost < outTempCU->m_totalCost)
             {
-                fprintf(fp1, "\n%d vs %d  : selected mode :N : %d , cost : %d , Part mode : %d , Pred Mode : %d ",
-                        outBestCU->getWidth(0) / 2, outTempCU->getWidth(0) / 2, outBestCU->getWidth(0) / 2, outBestCU->m_totalCost,
-                        outBestCU->getPartitionSize(0), outBestCU->getPredictionMode(0));
                 if (outBestCU->getPredictionMode(0) == MODE_INTER)
                 {
-                    cntInter[depth]++;
-                    if (outBestCU->getPartitionSize(0) < 3)
+                    m_log->cntInter[depth]++;
+                    if (outBestCU->getPartitionSize(0) < AMP_ID)
                     {
-                        cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
+                        m_log->cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
                     }
                     else
                     {
-                        cuInterDistribution[depth][3]++;
+                        m_log->cuInterDistribution[depth][AMP_ID]++;
                     }
                 }
                 else if (outBestCU->getPredictionMode(0) == MODE_INTRA)
                 {
-                    cntIntra[depth]++;
+                    m_log->cntIntra[depth]++;
                     if (outBestCU->getLumaIntraDir()[0] > 1)
                     {
-                        cuIntraDistribution[depth][2]++;
+                        m_log->cuIntraDistribution[depth][ANGULAR_MODE_ID]++;
                     }
                     else
                     {
-                        cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
+                        m_log->cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
                     }
                 }
             }
             else
             {
-                fprintf(fp1, "\n  %d vs %d  : selected mode :N : %d , cost : %d  ",
-                        outBestCU->getWidth(0) / 2, outTempCU->getWidth(0) / 2, outTempCU->getWidth(0) / 2, outTempCU->m_totalCost);
-                cntSplit[depth]++;
+                m_log->cntSplit[depth]++;
             }
         }
-#endif // if  LOGGING
 
         /* If Best Mode is not NULL; then compare costs. Else assign best mode to Sub-CU costs
          * Copy recon data from Temp structure to Best structure */
@@ -770,45 +741,43 @@
         }
     }
 
-#if CU_STAT_LOGFILE
-    if (depth == 3)
+    if (depth == g_maxCUDepth - 1)
     {
         if (!outBestCU->isSkipped(0))
         {
             if (outBestCU->getPredictionMode(0) == MODE_INTER)
             {
-                cntInter[depth]++;
-                if (outBestCU->getPartitionSize(0) < 3)
+                m_log->cntInter[depth]++;
+                if (outBestCU->getPartitionSize(0) < AMP_ID)
                 {
-                    cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
+                    m_log->cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
                 }
                 else
                 {
-                    cuInterDistribution[depth][3]++;
+                    m_log->cuInterDistribution[depth][AMP_ID]++;
                 }
             }
             else if (outBestCU->getPredictionMode(0) == MODE_INTRA)
             {
-                cntIntra[depth]++;
+                m_log->cntIntra[depth]++;
                 if (outBestCU->getPartitionSize(0) == SIZE_2Nx2N)
                 {
                     if (outBestCU->getLumaIntraDir()[0] > 1)
                     {
-                        cuIntraDistribution[depth][2]++;
+                        m_log->cuIntraDistribution[depth][ANGULAR_MODE_ID]++;
                     }
                     else
                     {
-                        cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
+                        m_log->cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
                     }
                 }
                 else if (outBestCU->getPartitionSize(0) == SIZE_NxN)
                 {
-                    cntIntraNxN++;
+                    m_log->cntIntraNxN++;
                 }
             }
         }
     }
-#endif // if LOGGING
 
     /* Copy Best data to Picture for next partition prediction. */
     outBestCU->copyToPic((UChar)depth);
@@ -818,6 +787,7 @@
 
     if (bBoundary || (bSliceEnd && bInsidePicture))
     {
+        m_log->cntTotalCu[depth]--;
         return;
     }
 
diff -r e2895ce7bbeb -r 96c180b4ed4f source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Sun Nov 17 11:24:13 2013 -0600
+++ b/source/encoder/encoder.cpp	Mon Nov 18 11:32:06 2013 +0530
@@ -374,6 +374,108 @@
                      m_numWPFrames, m_analyzeP.m_numPics, (float)100.0 * m_numWPFrames / m_analyzeP.m_numPics);
         }
     }
+    for (int sliceType = 2; sliceType >= 0; sliceType--)
+    {
+        StatisticLog finalLog;
+        for (int depth = 0; depth < (int)g_maxCUDepth; depth++)
+        {
+            double cntInter, cntIntra, cntSplit, cntSkipCu;
+            double cuInterDistribution[INTER_MODES], cuIntraDistribution[INTRA_MODES];
+            double cntIntraNxN = 0.0;
+            for (int j = 0; j < param.frameNumThreads; j++)
+            {
+                for (int row = 0; row < m_frameEncoder[0].m_numRows; row++)
+                {
+                    StatisticLog& enclog = m_frameEncoder[j].m_rows[row].m_cuCoder.m_sliceTypeLog[sliceType];
+                    finalLog.cntIntra[depth] += enclog.cntIntra[depth];
+                    finalLog.cntTotalCu[depth] += enclog.cntTotalCu[depth];
+                    if (sliceType != I_SLICE)
+                    {
+                        finalLog.cntInter[depth] += enclog.cntInter[depth];
+                        finalLog.cntSkipCu[depth] += enclog.cntSkipCu[depth];
+                        finalLog.cntSplit[depth] += enclog.cntSplit[depth];
+                        for (int m = 0; m < INTER_MODES; m++)
+                        {
+                            if (m < INTRA_MODES)
+                            {
+                                finalLog.cuIntraDistribution[depth][m] += enclog.cuIntraDistribution[depth][m];
+                            }
+                            finalLog.cuInterDistribution[depth][m] += enclog.cuInterDistribution[depth][m];
+                        }
+                        if (depth == (int)g_maxCUDepth - 1)
+                            finalLog.cntIntraNxN += enclog.cntIntraNxN;
+                    }
+                }
+            }
+            // check for 0/0, if true assign 0 else calculate percentage
+            for (int n = 0; n < INTER_MODES; n++)
+            {
+                if (finalLog.cntInter[depth] == 0)
+                    cuInterDistribution[n] = 0;
+                else
+                    cuInterDistribution[n] = (double)(finalLog.cuInterDistribution[depth][n] * 100) / (double)finalLog.cntInter[depth];
+                if (n < INTRA_MODES)
+                {
+                    if (finalLog.cntIntra[depth] == 0)
+                    {
+                        cntIntraNxN = 0;
+                        cuIntraDistribution[n] = 0;
+                    }
+                    else
+                    {
+                        cntIntraNxN = (double)(finalLog.cntIntraNxN * 100) / (double)finalLog.cntIntra[depth];
+                        cuIntraDistribution[n] = (double)(finalLog.cuIntraDistribution[depth][n] * 100) / (double)finalLog.cntIntra[depth];
+                    }
+                }
+            }
+            if (finalLog.cntTotalCu[depth] == 0)
+            {
+                cntInter = 0;
+                cntIntra = 0;
+                cntSplit = 0;
+                cntSkipCu = 0;
+            }
+            else
+            {
+                cntInter = (double)(finalLog.cntInter[depth] * 100) / (double)finalLog.cntTotalCu[depth];
+                cntIntra = (double)(finalLog.cntIntra[depth] * 100) / (double)finalLog.cntTotalCu[depth];
+                cntSplit = (double)(finalLog.cntSplit[depth] * 100) / (double)finalLog.cntTotalCu[depth];
+                cntSkipCu = (double)(finalLog.cntSkipCu[depth] * 100) / (double)finalLog.cntTotalCu[depth];
+            }
+            // print statistics
+            if (sliceType == I_SLICE)
+                x265_log(&param, X265_LOG_INFO, "Intra I%d   %.2f%%\n", g_maxCUWidth >> depth, cntIntra);
+            else
+            {
+                if (depth < (int)g_maxCUDepth - 1)
+                {
+                    if (sliceType == P_SLICE)
+                        x265_log(&param, X265_LOG_INFO, "Inter P%d   Inter %.2f%% (2Nx2N %.2f%%  Nx2N %.2f%%  2NxN %.2f%%  AMP %.2f%%)  "
+                                "Intra %.2f%% (DC %.2f%%  Planar %.2f%%  Ang %.2f%% )  Split %.2f%%  Skipped %.2f%% \n", g_maxCUWidth >> depth,
+                                cntInter, cuInterDistribution[0], cuInterDistribution[2], cuInterDistribution[1], cuInterDistribution[3],
+                                cntIntra, cuIntraDistribution[0], cuIntraDistribution[1], cuIntraDistribution[2], cntSplit, cntSkipCu);
+                    else
+                        x265_log(&param, X265_LOG_INFO, "Inter B%d   Inter %.2f%% (2Nx2N %.2f%%  Nx2N %.2f%%  2NxN %.2f%%  AMP %.2f%%)  "
+                                "Intra %.2f%% (DC %.2f%%  Planar %.2f%%  Ang %.2f%% )  Split %.2f%%  Skipped %.2f%% \n", g_maxCUWidth >> depth,
+                                cntInter, cuInterDistribution[0], cuInterDistribution[2], cuInterDistribution[1], cuInterDistribution[3],
+                                cntIntra, cuIntraDistribution[0], cuIntraDistribution[1], cuIntraDistribution[2], cntSplit, cntSkipCu);
+                }
+                else
+                {
+                    if (sliceType == P_SLICE)
+                        x265_log(&param, X265_LOG_INFO, "Inter P%d    Inter %.2f%% (2Nx2N %.2f%%  Nx2N %.2f%%  2NxN %.2f%%  AMP %.2f%%)  "
+                                "Intra %.2f%% (DC %.2f%%  Planar %.2f%%  Ang %.2f%%  NXN %.2f%%)  Skipped %.2f%% \n", g_maxCUWidth >> depth,
+                                cntInter, cuInterDistribution[0], cuInterDistribution[2], cuInterDistribution[1], cuInterDistribution[3],
+                                cntIntra, cuIntraDistribution[0], cuIntraDistribution[1], cuIntraDistribution[2], cntIntraNxN, cntSkipCu);
+                    else
+                        x265_log(&param, X265_LOG_INFO, "Inter B%d    Inter %.2f%% (2Nx2N %.2f%%  Nx2N %.2f%%  2NxN %.2f%%  AMP %.2f%%)  "
+                                "Intra %.2f%% (DC %.2f%%  Planar %.2f%%  Ang %.2f%%  NXN %.2f%%)  Skipped %.2f%% \n", g_maxCUWidth >> depth,
+                                cntInter, cuInterDistribution[0], cuInterDistribution[2], cuInterDistribution[1], cuInterDistribution[3],
+                                cntIntra, cuIntraDistribution[0], cuIntraDistribution[1], cuIntraDistribution[2], cntIntraNxN, cntSkipCu);
+                }
+            }
+        }
+    }
 }
 
 void Encoder::fetchStats(x265_stats *stats)
diff -r e2895ce7bbeb -r 96c180b4ed4f source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Sun Nov 17 11:24:13 2013 -0600
+++ b/source/encoder/frameencoder.cpp	Mon Nov 18 11:32:06 2013 +0530
@@ -36,13 +36,6 @@
 
 using namespace x265;
 
-#if CU_STAT_LOGFILE
-int cntInter[4], cntIntra[4], cntSplit[4],  totalCU;
-int cuInterDistribution[4][4], cuIntraDistribution[4][3], cntIntraNxN;
-int cntSkipCu[4], cntTotalCu[4];
-extern FILE * fp, * fp1;
-#endif
-
 enum SCALING_LIST_PARAMETER
 {
     SCALING_LIST_OFF,
@@ -269,6 +262,8 @@
     slice->setReferenced(true);
     slice->setScalingList(m_top->getScalingList());
     slice->getScalingList()->setUseTransformSkip(m_pps.getUseTransformSkip());
+    for (int i = 0; i < m_numRows; i++)
+        m_rows[i].m_cuCoder.m_log = &m_rows[i].m_cuCoder.m_sliceTypeLog[sliceType];
 
     if (slice->getPPS()->getDeblockingFilterControlPresentFlag())
     {
@@ -478,52 +473,11 @@
         }
     }
 
-#if CU_STAT_LOGFILE
-    for (int i = 0; i < 4; i++)
-    {
-        cntInter[i] = 0;
-        cntIntra[i] = 0;
-        cntSplit[i] = 0;
-        cntSkipCu[i] = 0;
-        cntTotalCu[i] = 0;
-        for (int j = 0; j < 4; j++)
-        {
-            if (j < 3)
-            {
-                cuIntraDistribution[i][j] = 0;
-            }
-            cuInterDistribution[i][j] = 0;
-        }
-    }
-
-    totalCU = 0;
-    cntIntraNxN = 0;
-#endif // if CU_STAT_LOGFILE
-
     // Analyze CTU rows, most of the hard work is done here
     // frame is compressed in a wave-front pattern if WPP is enabled. Loop filter runs as a
     // wave-front behind the CU compression and reconstruction
     compressCTURows();
 
-#if CU_STAT_LOGFILE
-    if (slice->getSliceType() != I_SLICE)
-    {
-        fprintf(fp, " FRAME  - Inter FRAME \n");
-        fprintf(fp, "64x64 : Inter [%.2f %%  (2Nx2N %.2f %%,  Nx2N %.2f %% , 2NxN %.2f %%, AMP %.2f %%)] Intra [%.2f %%(DC %.2f %% Planar %.2f %% Ang %.2f%% )] Split[%.2f] %% Skipped[%.2f]%% \n", (double)(cntInter[0] * 100) / cntTotalCu[0], (double)(cuInterDistribution[0][0] * 100) / cntInter[0],  (double)(cuInterDistribution[0][2] * 100) / cntInter[0], (double)(cuInterDistribution[0][1] * 100) / cntInter[0], (double)(cuInterDistribution[0][3] * 100) / cntInter[0], (double)(cntIntra[0] * 100) / cntTotalCu[0], (double)(cuIntraDistribution[0][0] * 100) / cntIntra[0], (double)(cuIntraDistribution[0][1] * 100) / cntIntra[0], (double)(cuIntraDistribution[0][2] * 100) / cntIntra[0], (double)(cntSplit[0] * 100) / cntTotalCu[0], (double)(cntSkipCu[0] * 100) / cntTotalCu[0]);
-        fprintf(fp, "32x32 : Inter [%.2f %% (2Nx2N %.2f %%,  Nx2N %.2f %%, 2NxN %.2f %%, AMP %.2f %%)] Intra [%.2f %%(DC %.2f %% Planar %.2f %% Ang %.2f %% )] Split[%.2f] %% Skipped[%.2f] %%\n", (double)(cntInter[1] * 100) / cntTotalCu[1], (double)(cuInterDistribution[1][0] * 100) / cntInter[1],  (double)(cuInterDistribution[1][2] * 100) / cntInter[1], (double)(cuInterDistribution[1][1] * 100) / cntInter[1], (double)(cuInterDistribution[1][3] * 100) / cntInter[1], (double)(cntIntra[1] * 100) / cntTotalCu[1], (double)(cuIntraDistribution[1][0] * 100) / cntIntra[1], (double)(cuIntraDistribution[1][1] * 100) / cntIntra[1], (double)(cuIntraDistribution[1][2] * 100) / cntIntra[1], (double)(cntSplit[1] * 100) / cntTotalCu[1], (double)(cntSkipCu[1] * 100) / cntTotalCu[1]);
-        fprintf(fp, "16x16 : Inter [%.2f %% (2Nx2N %.2f %%,  Nx2N %.2f %%, 2NxN %.2f %%, AMP %.2f %%)] Intra [%.2f %%(DC %.2f %% Planar %.2f %% Ang %.2f %% )] Split[%.2f] %% Skipped[%.2f]%% \n", (double)(cntInter[2] * 100) / cntTotalCu[2], (double)(cuInterDistribution[2][0] * 100) / cntInter[2],  (double)(cuInterDistribution[2][2] * 100) / cntInter[2], (double)(cuInterDistribution[2][1] * 100) / cntInter[2], (double)(cuInterDistribution[2][3] * 100) / cntInter[2], (double)(cntIntra[2] * 100) / cntTotalCu[2], (double)(cuIntraDistribution[2][0] * 100) / cntIntra[2], (double)(cuIntraDistribution[2][1] * 100) / cntIntra[2], (double)(cuIntraDistribution[2][2] * 100) / cntIntra[2], (double)(cntSplit[2] * 100) / cntTotalCu[2], (double)(cntSkipCu[2] * 100) / cntTotalCu[2]);
-        fprintf(fp, "8x8 : Inter [%.2f %% (2Nx2N %.2f %%,  Nx2N %.2f %%, 2NxN %.2f %%, AMP %.2f %%)] Intra [%.2f %%(DC %.2f  %% Planar %.2f %% Ang %.2f %%) NxN[%.2f] %% ] Skipped[%.2f] %% \n \n", (double)(cntInter[3] * 100) / cntTotalCu[3], (double)(cuInterDistribution[3][0] * 100) / cntInter[3],  (double)(cuInterDistribution[3][2] * 100) / cntInter[3], (double)(cuInterDistribution[3][1] * 100) / cntInter[3], (double)(cuInterDistribution[3][3] * 100) / cntInter[3], (double)((cntIntra[3]) * 100) / cntTotalCu[3], (double)(cuIntraDistribution[3][0] * 100) / cntIntra[3], (double)(cuIntraDistribution[3][1] * 100) / cntIntra[3], (double)(cuIntraDistribution[3][2] * 100) / cntIntra[3], (double)(cntIntraNxN * 100) / cntIntra[3], (double)(cntSkipCu[3] * 100) / cntTotalCu[3]);
-    }
-    else
-    {
-        fprintf(fp, " FRAME - Intra FRAME \n");
-        fprintf(fp, "64x64 : Intra [%.2f %%] Skipped [%.2f %%]\n", (double)(cntIntra[0] * 100) / cntTotalCu[0], (double)(cntSkipCu[0] * 100) / cntTotalCu[0]);
-        fprintf(fp, "32x32 : Intra [%.2f %%] Skipped [%.2f %%] \n", (double)(cntIntra[1] * 100) / cntTotalCu[1], (double)(cntSkipCu[1] * 100) / cntTotalCu[1]);
-        fprintf(fp, "16x16 : Intra [%.2f %%] Skipped [%.2f %%]\n", (double)(cntIntra[2] * 100) / cntTotalCu[2], (double)(cntSkipCu[2] * 100) / cntTotalCu[2]);
-        fprintf(fp, "8x8   : Intra [%.2f %%] Skipped [%.2f %%]\n", (double)(cntIntra[3] * 100) / cntTotalCu[3], (double)(cntSkipCu[3] * 100) / cntTotalCu[3]);
-    }
-#endif // if LOGGING
-
     if (m_cfg->param.bEnableWavefront)
     {
         slice->setNextSlice(true);
diff -r e2895ce7bbeb -r 96c180b4ed4f source/encoder/frameencoder.h
--- a/source/encoder/frameencoder.h	Sun Nov 17 11:24:13 2013 -0600
+++ b/source/encoder/frameencoder.h	Mon Nov 18 11:32:06 2013 +0530
@@ -159,6 +159,8 @@
     Event                    m_done;
     bool                     m_threadActive;
 
+    int                      m_numRows;
+    CTURow*                  m_rows;
     SEIWriter                m_seiWriter;
     TComSPS                  m_sps;
     TComPPS                  m_pps;
@@ -184,9 +186,7 @@
     NALUnitEBSP*             m_nalList[MAX_NAL_UNITS];
     int                      m_nalCount;
 
-    int                      m_numRows;
     int                      m_filterRowDelay;
-    CTURow*                  m_rows;
     Event                    m_completionEvent;
     int64_t                  m_totalTime;
 };
diff -r e2895ce7bbeb -r 96c180b4ed4f source/x265.cpp
--- a/source/x265.cpp	Sun Nov 17 11:24:13 2013 -0600
+++ b/source/x265.cpp	Mon Nov 18 11:32:06 2013 +0530
@@ -144,11 +144,6 @@
     { 0, 0, 0, 0 }
 };
 
-#if CU_STAT_LOGFILE
-FILE* fp = NULL;
-FILE * fp1 = NULL;
-#endif
-
 /* Ctrl-C handler */
 static volatile sig_atomic_t b_ctrl_c /* = 0 */;
 static void sigint_handler(int)
@@ -569,11 +564,6 @@
 #endif
     PPA_INIT();
 
-#if CU_STAT_LOGFILE
-    fp = fopen("Log_CU_stats.txt", "w");
-    fp1 = fopen("LOG_CU_COST.txt", "w");
-#endif
-
     x265_param param;
     CLIOptions   cliopt;
 
@@ -694,9 +684,5 @@
 #if HAVE_VLD
     assert(VLDReportLeaks() == 0);
 #endif
-#if CU_STAT_LOGFILE
-    fclose(fp);
-    fclose(fp1);
-#endif
     return 0;
 }


More information about the x265-devel mailing list