[x265] [PATCH] log: output intra type statistics of I frame, bug fix in intra percentage calculation

kavitha at multicorewareinc.com kavitha at multicorewareinc.com
Thu Nov 28 06:40:00 CET 2013


# HG changeset patch
# User Kavitha Sampath <kavitha at multicorewareinc.com>
# Date 1385616934 -19800
#      Thu Nov 28 11:05:34 2013 +0530
# Branch stable
# Node ID 8519dc4a5b9e53f1ed6f2f52294d7caea2803bc3
# Parent  f92e0c49a9f0a0e6f6db3eb247bd04431eb75b1e
log: output intra type statistics of I frame, bug fix in intra percentage calculation

diff -r f92e0c49a9f0 -r 8519dc4a5b9e source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp	Wed Nov 27 20:50:08 2013 -0600
+++ b/source/Lib/TLibEncoder/TEncCu.cpp	Thu Nov 28 11:05:34 2013 +0530
@@ -551,6 +551,11 @@
     }
 
     outTempCU->initEstData(depth, qp);
+    if (depth < g_maxCUDepth - 2)
+    {
+        memcpy(m_log->tempIntra[depth], m_log->cntIntra, sizeof(m_log->cntIntra));
+        memcpy(m_log->tempIntraDist[depth], m_log->cuIntraDistribution, sizeof(m_log->cuIntraDistribution));
+    }
 
     // further split
     if (bSubBranch && bTrySplitDQP && depth < g_maxCUDepth - g_addCUDepth)
@@ -575,19 +580,9 @@
                     m_rdSbacCoders[nextDepth][CI_CURR_BEST]->load(m_rdSbacCoders[nextDepth][CI_NEXT_BEST]);
                 }
 
-                // The following if condition has to be commented out in case the early Abort based on comparison of parentCu cost, childCU cost is not required.
-                if (outBestCU->isIntra(0))
-                {
-                    xCompressIntraCU(subBestPartCU[partUnitIdx], subTempPartCU[partUnitIdx], nextDepth);
-                }
-                else
-                {
-                    xCompressIntraCU(subBestPartCU[partUnitIdx], subTempPartCU[partUnitIdx], nextDepth);
-                }
-                {
-                    outTempCU->copyPartFrom(subBestPartCU[partUnitIdx], partUnitIdx, nextDepth); // Keep best part data to current temporary data.
-                    xCopyYuv2Tmp(subBestPartCU[partUnitIdx]->getTotalNumPart() * partUnitIdx, nextDepth);
-                }
+                xCompressIntraCU(subBestPartCU[partUnitIdx], subTempPartCU[partUnitIdx], nextDepth);
+                outTempCU->copyPartFrom(subBestPartCU[partUnitIdx], partUnitIdx, nextDepth); // Keep best part data to current temporary data.
+                xCopyYuv2Tmp(subBestPartCU[partUnitIdx]->getTotalNumPart() * partUnitIdx, nextDepth);
             }
             else if (bInSlice)
             {
@@ -635,28 +630,39 @@
         m_rdSbacCoders[nextDepth][CI_NEXT_BEST]->store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
         if (outBestCU->m_totalCost < outTempCU->m_totalCost)
         {
+            if (depth < g_maxCUDepth - 2)
+            {
+                memcpy(m_log->cntIntra, m_log->tempIntra[depth], sizeof(m_log->tempIntra[depth]));
+                memcpy(m_log->cuIntraDistribution, m_log->tempIntraDist[depth], sizeof(m_log->tempIntraDist[depth]));
+            }
             m_log->cntIntra[depth]++;
-            for (int i = 0; i < 4; i++)
+            if (outBestCU->getLumaIntraDir()[0] > 1)
+                m_log->cuIntraDistribution[depth][ANGULAR_MODE_ID]++;
+            else
+                m_log->cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
+        }
+        else
+        {
+            if (depth == g_maxCUDepth - 2)
             {
-                if (outTempCU->getPartitionSize(i) != SIZE_NxN)
-                    m_log->cntIntra[depth + 1]--;
-                else
-                    m_log->cntIntraNxN--;
+                for (int i = 0; i < 16; i = i + 4)
+                {
+                    if (outTempCU->getPartitionSize(i) != SIZE_NxN)
+                    {
+                        m_log->cntIntra[depth + 1]++;
+                        if (outTempCU->getLumaIntraDir()[i] > 1)
+                            m_log->cuIntraDistribution[depth + 1][ANGULAR_MODE_ID]++;
+                        else
+                            m_log->cuIntraDistribution[depth + 1][outTempCU->getLumaIntraDir()[i]]++;
+                    }
+                    else
+                        m_log->cntIntraNxN++;
+                }
             }
-            m_log->cntIntra[depth + 1] += boundaryCu;
         }
         xCheckBestMode(outBestCU, outTempCU, depth); // RD compare current prediction with split prediction.
     }
 
-    if (depth == g_maxCUDepth - 1 && bSubBranch)
-    {
-        if (outBestCU->getPartitionSize(0) == SIZE_NxN)
-        {
-            m_log->cntIntraNxN++;
-        }
-        else
-            m_log->cntIntra[depth]++;
-    }
     outBestCU->copyToPic(depth); // Copy Best data to Picture for next partition prediction.
 
     // Copy Yuv data to picture Yuv
diff -r f92e0c49a9f0 -r 8519dc4a5b9e source/Lib/TLibEncoder/TEncCu.h
--- a/source/Lib/TLibEncoder/TEncCu.h	Wed Nov 27 20:50:08 2013 -0600
+++ b/source/Lib/TLibEncoder/TEncCu.h	Thu Nov 28 11:05:34 2013 +0530
@@ -66,6 +66,8 @@
     uint64_t cntIntraNxN;
     uint64_t cntSkipCu[4];
     uint64_t cntTotalCu[4];
+    uint64_t tempIntra[2][4];
+    uint64_t tempIntraDist[2][4][3];
 
     StatisticLog()
     {
diff -r f92e0c49a9f0 -r 8519dc4a5b9e source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Wed Nov 27 20:50:08 2013 -0600
+++ b/source/encoder/encoder.cpp	Thu Nov 28 11:05:34 2013 +0530
@@ -372,10 +372,9 @@
             continue;
 
         StatisticLog finalLog;
-        uint64_t cntIntraNxN = 0, cntIntra[4];
         for (int depth = 0; depth < (int)g_maxCUDepth; depth++)
         {
-            uint64_t cntInter, cntSplit, cntSkipCu;
+            uint64_t cntInter, cntSplit, cntSkipCu, cntIntra, cntIntraNxN;
             uint64_t cuInterDistribution[INTER_MODES], cuIntraDistribution[INTRA_MODES];
             for (int j = 0; j < param.frameNumThreads; j++)
             {
@@ -389,14 +388,14 @@
                         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++)
+                    }
+                    for (int m = 0; m < INTER_MODES; m++)
+                    {
+                        if (m < INTRA_MODES)
                         {
-                            if (m < INTRA_MODES)
-                            {
-                                finalLog.cuIntraDistribution[depth][m] += enclog.cuIntraDistribution[depth][m];
-                            }
-                            finalLog.cuInterDistribution[depth][m] += enclog.cuInterDistribution[depth][m];
+                            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;
@@ -426,28 +425,28 @@
             if (finalLog.cntTotalCu[depth] == 0)
             {
                 cntInter = 0;
-                cntIntra[depth] = 0;
+                cntIntra = 0;
                 cntSplit = 0;
                 cntSkipCu = 0;
             }
             else
             {
                 cntInter = (finalLog.cntInter[depth] * 100) / finalLog.cntTotalCu[depth];
-                cntIntra[depth] = (finalLog.cntIntra[depth] * 100) / finalLog.cntTotalCu[depth];
+                cntIntra = (finalLog.cntIntra[depth] * 100) / finalLog.cntTotalCu[depth];
                 cntSplit = (finalLog.cntSplit[depth] * 100) / finalLog.cntTotalCu[depth];
                 cntSkipCu = (finalLog.cntSkipCu[depth] * 100) / finalLog.cntTotalCu[depth];
                 if (sliceType == I_SLICE)
                     cntIntraNxN = (finalLog.cntIntraNxN * 100) / finalLog.cntTotalCu[depth];
             }
             // print statistics
+            int cuSize = g_maxCUWidth >> depth;
+            char stats[256] = {NULL};
+            int len = 0;
             if (sliceType != I_SLICE)
             {
-                char stats[256];
-                int len;
-
-                int cuSize = g_maxCUWidth >> depth;
-                len = sprintf(stats, "Split "LL"%% Merge "LL"%% Inter "LL"%%",
-                              cntSplit, cntSkipCu, cntInter);
+                if (depth != (int)g_maxCUDepth - 1)
+                    len = sprintf(stats, "Split "LL"%% ", cntSplit);
+                len += sprintf(stats + len, "Merge "LL"%% Inter "LL"%%", cntSkipCu, cntInter);
 
                 if (param.bEnableAMP)
                     len += sprintf(stats + len, "(%dx%d "LL"%% %dx%d "LL"%% %dx%d "LL"%% AMP "LL"%%)",
@@ -461,29 +460,27 @@
                                    cuSize/2, cuSize, cuInterDistribution[2],
                                    cuSize, cuSize/2, cuInterDistribution[1]);
 
-                if (cntIntra[depth])
+            }
+            if (cntIntra)
+            {
+                len += sprintf(stats + len, "Intra "LL"%%(DC "LL"%% P "LL"%% Ang "LL"%%",
+                                cntIntra, cuIntraDistribution[0],
+                                cuIntraDistribution[1], cuIntraDistribution[2]);
+                if (sliceType != I_SLICE)
                 {
-                    len += sprintf(stats + len, " Intra "LL"%%(DC "LL"%% P "LL"%% Ang "LL"%%",
-                                   cntIntra[depth], cuIntraDistribution[0],
-                                   cuIntraDistribution[1], cuIntraDistribution[2]);
                     if (depth == (int)g_maxCUDepth - 1)
                         len += sprintf(stats + len, " %dx%d "LL"%%", cuSize/2, cuSize/2, cntIntraNxN);
-                    len += sprintf(stats + len, ")");
                 }
 
-                x265_log(&param, X265_LOG_INFO, "%c%-2d: %s\n", sliceType == P_SLICE ? 'P' : 'B', cuSize, stats);
+                len += sprintf(stats + len, ")");
+                if (sliceType == I_SLICE)
+                {
+                    if (depth == (int)g_maxCUDepth - 1)
+                        len += sprintf(stats + len, " %dx%d: "LL"%%", cuSize/2, cuSize/2, cntIntraNxN);
+                }
             }
-        }
-        if (sliceType == I_SLICE)
-        {
-            char stats[50];
-            if (g_maxCUDepth == 4)
-                sprintf(stats, LL"%%  "LL"%%  "LL"%%  "LL"%%  "LL"%%", cntIntra[0], cntIntra[1], cntIntra[2], cntIntra[3], cntIntraNxN);
-            else if (g_maxCUDepth == 3)
-                sprintf(stats, LL"%%  "LL"%%  "LL"%%  "LL"%%", cntIntra[0], cntIntra[1], cntIntra[2], cntIntraNxN);
-            else
-                sprintf(stats, LL"%%  "LL"%%  "LL"%%", cntIntra[0], cntIntra[1], cntIntraNxN);
-            x265_log(&param, X265_LOG_INFO, "I-frame %d..4:  %s\n", g_maxCUWidth, stats);
+            if (stats[0])
+                x265_log(&param, X265_LOG_INFO, "%c%-2d: %s\n", sliceType == P_SLICE ? 'P' : sliceType == B_SLICE ? 'B' : 'I', cuSize, stats);
         }
     }
     if (param.logLevel >= X265_LOG_INFO)


More information about the x265-devel mailing list