[x265] [PATCH] stats: average luma and chroma distortion per frame

Divya Manivannan divya at multicorewareinc.com
Mon Jul 13 12:37:03 CEST 2015


# HG changeset patch
# User Divya Manivannan <divya at multicorewareinc.com>
# Date 1436783436 -19800
#      Mon Jul 13 16:00:36 2015 +0530
# Node ID c36667ada0c9612e0369c1763cd90da5b69951c1
# Parent  46606dd51913f7b4a73b49ff3bd059ad85e35cea
stats: average luma and chroma distortion per frame

diff -r 46606dd51913 -r c36667ada0c9 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Wed Jul 01 14:36:18 2015 +0530
+++ b/source/CMakeLists.txt	Mon Jul 13 16:00:36 2015 +0530
@@ -30,7 +30,7 @@
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 64)
+set(X265_BUILD 65)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 46606dd51913 -r c36667ada0c9 source/common/framedata.h
--- a/source/common/framedata.h	Wed Jul 01 14:36:18 2015 +0530
+++ b/source/common/framedata.h	Mon Jul 13 16:00:36 2015 +0530
@@ -52,6 +52,8 @@
     double      percent8x8Intra;
     double      percent8x8Inter;
     double      percent8x8Skip;
+    double      avgLumaDistortion;
+    double      avgChromaDistortion;
     double      percentIntraNxN;
     double      percentSkipCu[NUM_CU_DEPTH];
     double      percentMergeCu[NUM_CU_DEPTH];
@@ -60,6 +62,9 @@
 
     uint64_t    cntIntraNxN;
     uint64_t    totalCu;
+    uint64_t    totalCtu;
+    uint64_t    lumaDistortion;
+    uint64_t    chromaDistortion;
     uint64_t    cntSkipCu[NUM_CU_DEPTH];
     uint64_t    cntMergeCu[NUM_CU_DEPTH];
     uint64_t    cntInter[NUM_CU_DEPTH];
diff -r 46606dd51913 -r c36667ada0c9 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Wed Jul 01 14:36:18 2015 +0530
+++ b/source/encoder/encoder.cpp	Mon Jul 13 16:00:36 2015 +0530
@@ -1165,6 +1165,8 @@
         frameStats->countRowBlocks = curEncoder->m_countRowBlocks;
 
         frameStats->cuStats.percentIntraNxN = curFrame->m_encData->m_frameStats.percentIntraNxN;
+        frameStats->avgChromaDistortion     = curFrame->m_encData->m_frameStats.avgChromaDistortion;
+        frameStats->avgLumaDistortion       = curFrame->m_encData->m_frameStats.avgLumaDistortion;
         for (uint32_t depth = 0; depth <= g_maxCUDepth; depth++)
         {
             frameStats->cuStats.percentSkipCu[depth]  = curFrame->m_encData->m_frameStats.percentSkipCu[depth];
diff -r 46606dd51913 -r c36667ada0c9 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Wed Jul 01 14:36:18 2015 +0530
+++ b/source/encoder/frameencoder.cpp	Mon Jul 13 16:00:36 2015 +0530
@@ -585,8 +585,11 @@
     }
     for (uint32_t i = 0; i < m_numRows; i++)
     {
-        m_frame->m_encData->m_frameStats.cntIntraNxN += m_rows[i].rowStats.cntIntraNxN;
-        m_frame->m_encData->m_frameStats.totalCu     += m_rows[i].rowStats.totalCu;
+        m_frame->m_encData->m_frameStats.cntIntraNxN      += m_rows[i].rowStats.cntIntraNxN;
+        m_frame->m_encData->m_frameStats.totalCu          += m_rows[i].rowStats.totalCu;
+        m_frame->m_encData->m_frameStats.totalCtu         += m_rows[i].rowStats.totalCtu;
+        m_frame->m_encData->m_frameStats.lumaDistortion   += m_rows[i].rowStats.lumaDistortion;
+        m_frame->m_encData->m_frameStats.chromaDistortion += m_rows[i].rowStats.chromaDistortion;
         for (uint32_t depth = 0; depth <= g_maxCUDepth; depth++)
         {
             m_frame->m_encData->m_frameStats.cntSkipCu[depth] += m_rows[i].rowStats.cntSkipCu[depth];
@@ -597,7 +600,9 @@
                 m_frame->m_encData->m_frameStats.cuIntraDistribution[depth][n] += m_rows[i].rowStats.cuIntraDistribution[depth][n];
         }
     }
-    m_frame->m_encData->m_frameStats.percentIntraNxN = (double)(m_frame->m_encData->m_frameStats.cntIntraNxN * 100) / m_frame->m_encData->m_frameStats.totalCu;
+    m_frame->m_encData->m_frameStats.avgLumaDistortion   = (double)(m_frame->m_encData->m_frameStats.lumaDistortion / m_frame->m_encData->m_frameStats.totalCtu);
+    m_frame->m_encData->m_frameStats.avgChromaDistortion = (double)(m_frame->m_encData->m_frameStats.chromaDistortion / m_frame->m_encData->m_frameStats.totalCtu);
+    m_frame->m_encData->m_frameStats.percentIntraNxN     = (double)(m_frame->m_encData->m_frameStats.cntIntraNxN * 100) / m_frame->m_encData->m_frameStats.totalCu;
     for (uint32_t depth = 0; depth <= g_maxCUDepth; depth++)
     {
         m_frame->m_encData->m_frameStats.percentSkipCu[depth]  = (double)(m_frame->m_encData->m_frameStats.cntSkipCu[depth] * 100) / m_frame->m_encData->m_frameStats.totalCu;
@@ -961,8 +966,11 @@
                 curRow.rowStats.skip8x8Cnt  += (int)(frameLog.cntSkipCu[depth] << shift);
             }
         }
-        curRow.rowStats.cntIntraNxN += frameLog.cntIntraNxN;
-        curRow.rowStats.totalCu     += frameLog.totalCu;
+        curRow.rowStats.totalCtu++;
+        curRow.rowStats.lumaDistortion   += best.lumaDistortion;
+        curRow.rowStats.chromaDistortion += best.chromaDistortion;
+        curRow.rowStats.cntIntraNxN      += frameLog.cntIntraNxN;
+        curRow.rowStats.totalCu          += frameLog.totalCu;
         for (uint32_t depth = 0; depth <= g_maxCUDepth; depth++)
         {
             curRow.rowStats.cntSkipCu[depth] += frameLog.cntSkipCu[depth];
diff -r 46606dd51913 -r c36667ada0c9 source/encoder/search.cpp
--- a/source/encoder/search.cpp	Wed Jul 01 14:36:18 2015 +0530
+++ b/source/encoder/search.cpp	Mon Jul 13 16:00:36 2015 +0530
@@ -1162,8 +1162,9 @@
     cu.getIntraTUQtDepthRange(tuDepthRange, 0);
 
     intraMode.initCosts();
-    intraMode.distortion += estIntraPredQT(intraMode, cuGeom, tuDepthRange, sharedModes);
-    intraMode.distortion += estIntraPredChromaQT(intraMode, cuGeom, sharedChromaModes);
+    intraMode.lumaDistortion += estIntraPredQT(intraMode, cuGeom, tuDepthRange, sharedModes);
+    intraMode.chromaDistortion += estIntraPredChromaQT(intraMode, cuGeom, sharedChromaModes);
+    intraMode.distortion += intraMode.lumaDistortion + intraMode.chromaDistortion;
 
     m_entropyCoder.resetBits();
     if (m_slice->m_pps->bTransquantBypassEnabled)
@@ -1378,8 +1379,9 @@
     codeIntraLumaQT(intraMode, cuGeom, 0, 0, false, icosts, tuDepthRange);
     extractIntraResultQT(cu, *reconYuv, 0, 0);
 
-    intraMode.distortion = icosts.distortion;
-    intraMode.distortion += estIntraPredChromaQT(intraMode, cuGeom, NULL);
+    intraMode.lumaDistortion = icosts.distortion;
+    intraMode.chromaDistortion = estIntraPredChromaQT(intraMode, cuGeom, NULL);
+    intraMode.distortion = intraMode.lumaDistortion + intraMode.chromaDistortion;
 
     m_entropyCoder.resetBits();
     if (m_slice->m_pps->bTransquantBypassEnabled)
@@ -2460,10 +2462,11 @@
 
     // Luma
     int part = partitionFromLog2Size(cu.m_log2CUSize[0]);
-    interMode.distortion = primitives.cu[part].sse_pp(fencYuv->m_buf[0], fencYuv->m_size, reconYuv->m_buf[0], reconYuv->m_size);
+    interMode.lumaDistortion = primitives.cu[part].sse_pp(fencYuv->m_buf[0], fencYuv->m_size, reconYuv->m_buf[0], reconYuv->m_size);
     // Chroma
-    interMode.distortion += m_rdCost.scaleChromaDist(1, primitives.chroma[m_csp].cu[part].sse_pp(fencYuv->m_buf[1], fencYuv->m_csize, reconYuv->m_buf[1], reconYuv->m_csize));
-    interMode.distortion += m_rdCost.scaleChromaDist(2, primitives.chroma[m_csp].cu[part].sse_pp(fencYuv->m_buf[2], fencYuv->m_csize, reconYuv->m_buf[2], reconYuv->m_csize));
+    interMode.chromaDistortion = m_rdCost.scaleChromaDist(1, primitives.chroma[m_csp].cu[part].sse_pp(fencYuv->m_buf[1], fencYuv->m_csize, reconYuv->m_buf[1], reconYuv->m_csize));
+    interMode.chromaDistortion += m_rdCost.scaleChromaDist(2, primitives.chroma[m_csp].cu[part].sse_pp(fencYuv->m_buf[2], fencYuv->m_csize, reconYuv->m_buf[2], reconYuv->m_csize));
+    interMode.distortion = interMode.lumaDistortion + interMode.chromaDistortion;
 
     m_entropyCoder.load(m_rqt[depth].cur);
     m_entropyCoder.resetBits();
@@ -2584,14 +2587,16 @@
         reconYuv->copyFromYuv(*predYuv);
 
     // update with clipped distortion and cost (qp estimation loop uses unclipped values)
-    uint32_t bestDist = primitives.cu[sizeIdx].sse_pp(fencYuv->m_buf[0], fencYuv->m_size, reconYuv->m_buf[0], reconYuv->m_size);
-    bestDist += m_rdCost.scaleChromaDist(1, primitives.chroma[m_csp].cu[sizeIdx].sse_pp(fencYuv->m_buf[1], fencYuv->m_csize, reconYuv->m_buf[1], reconYuv->m_csize));
-    bestDist += m_rdCost.scaleChromaDist(2, primitives.chroma[m_csp].cu[sizeIdx].sse_pp(fencYuv->m_buf[2], fencYuv->m_csize, reconYuv->m_buf[2], reconYuv->m_csize));
+    uint32_t bestLumaDist = primitives.cu[sizeIdx].sse_pp(fencYuv->m_buf[0], fencYuv->m_size, reconYuv->m_buf[0], reconYuv->m_size);
+    uint32_t bestChromaDist = m_rdCost.scaleChromaDist(1, primitives.chroma[m_csp].cu[sizeIdx].sse_pp(fencYuv->m_buf[1], fencYuv->m_csize, reconYuv->m_buf[1], reconYuv->m_csize));
+    bestChromaDist += m_rdCost.scaleChromaDist(2, primitives.chroma[m_csp].cu[sizeIdx].sse_pp(fencYuv->m_buf[2], fencYuv->m_csize, reconYuv->m_buf[2], reconYuv->m_csize));
     if (m_rdCost.m_psyRd)
         interMode.psyEnergy = m_rdCost.psyCost(sizeIdx, fencYuv->m_buf[0], fencYuv->m_size, reconYuv->m_buf[0], reconYuv->m_size);
 
     interMode.totalBits = bits;
-    interMode.distortion = bestDist;
+    interMode.lumaDistortion = bestLumaDist;
+    interMode.chromaDistortion = bestChromaDist;
+    interMode.distortion = bestLumaDist + bestChromaDist;
     interMode.coeffBits = coeffBits;
     interMode.mvBits = bits - coeffBits;
     updateModeCost(interMode);
diff -r 46606dd51913 -r c36667ada0c9 source/encoder/search.h
--- a/source/encoder/search.h	Wed Jul 01 14:36:18 2015 +0530
+++ b/source/encoder/search.h	Mon Jul 13 16:00:36 2015 +0530
@@ -109,6 +109,8 @@
     uint64_t   sa8dCost;   // sum of partition sa8d distortion costs   (sa8d(fenc, pred) + lambda * bits)
     uint32_t   sa8dBits;   // signal bits used in sa8dCost calculation
     uint32_t   psyEnergy;  // sum of partition psycho-visual energy difference
+    uint32_t   lumaDistortion;
+    uint32_t   chromaDistortion;
     uint32_t   distortion; // sum of partition SSE distortion
     uint32_t   totalBits;  // sum of partition bits (mv + coeff)
     uint32_t   mvBits;     // Mv bits + Ref + block type (or intra mode)
@@ -120,6 +122,8 @@
         sa8dCost = 0;
         sa8dBits = 0;
         psyEnergy = 0;
+        lumaDistortion = 0;
+        chromaDistortion = 0;
         distortion = 0;
         totalBits = 0;
         mvBits = 0;
@@ -133,6 +137,8 @@
         sa8dCost = UINT64_MAX / 2;
         sa8dBits = MAX_UINT / 2;
         psyEnergy = MAX_UINT / 2;
+        lumaDistortion = MAX_UINT / 2;
+        chromaDistortion = MAX_UINT / 2;
         distortion = MAX_UINT / 2;
         totalBits = MAX_UINT / 2;
         mvBits = MAX_UINT / 2;
@@ -145,6 +151,8 @@
                  sa8dCost >= UINT64_MAX / 2 ||
                  sa8dBits >= MAX_UINT / 2 ||
                  psyEnergy >= MAX_UINT / 2 ||
+                 lumaDistortion >= MAX_UINT / 2 ||
+                 chromaDistortion >= MAX_UINT / 2 ||
                  distortion >= MAX_UINT / 2 ||
                  totalBits >= MAX_UINT / 2 ||
                  mvBits >= MAX_UINT / 2 ||
@@ -159,6 +167,8 @@
         sa8dCost += subMode.sa8dCost;
         sa8dBits += subMode.sa8dBits;
         psyEnergy += subMode.psyEnergy;
+        lumaDistortion += subMode.lumaDistortion;
+        chromaDistortion += subMode.chromaDistortion;
         distortion += subMode.distortion;
         totalBits += subMode.totalBits;
         mvBits += subMode.mvBits;
diff -r 46606dd51913 -r c36667ada0c9 source/x265-extras.cpp
--- a/source/x265-extras.cpp	Wed Jul 01 14:36:18 2015 +0530
+++ b/source/x265-extras.cpp	Mon Jul 13 16:00:36 2015 +0530
@@ -107,6 +107,7 @@
                         fprintf(csvfp, ", Merge %dx%d", size, size);
                         size /= 2;
                     }
+                    fprintf(csvfp, ", Avg Luma Distortion, Avg Chroma Distortion");
                 }
                 fprintf(csvfp, "\n");
             }
@@ -178,6 +179,7 @@
             fprintf(csvfp, ", %5.2lf%%", frameStats->cuStats.percentSkipCu[depth]);
         for (uint32_t depth = 0; depth <= g_maxCUDepth; depth++)
             fprintf(csvfp, ", %5.2lf%%", frameStats->cuStats.percentMergeCu[depth]);
+        fprintf(csvfp, ", %.2lf, %.2lf", frameStats->avgLumaDistortion, frameStats->avgChromaDistortion);
     }
     fprintf(csvfp, "\n");
     fflush(stderr);
diff -r 46606dd51913 -r c36667ada0c9 source/x265.h
--- a/source/x265.h	Wed Jul 01 14:36:18 2015 +0530
+++ b/source/x265.h	Mon Jul 13 16:00:36 2015 +0530
@@ -129,6 +129,8 @@
     double           totalCTUTime;
     double           stallTime;
     double           avgWPP;
+    double           avgLumaDistortion;
+    double           avgChromaDistortion;
     uint64_t         bits;
     int              encoderOrder;
     int              poc;


More information about the x265-devel mailing list