[x265] [PATCH] log: collect statistics after CU analysis
kavitha at multicorewareinc.com
kavitha at multicorewareinc.com
Thu Dec 5 06:40:15 CET 2013
# HG changeset patch
# User Kavitha Sampath <kavitha at multicorewareinc.com>
# Date 1386221662 -19800
# Thu Dec 05 11:04:22 2013 +0530
# Node ID 8e33ade4dac29404a97224b1b0ac1982298399af
# Parent d35b423823312ab5cdc51d2d144d8b9b2c008c66
log: collect statistics after CU analysis
Report percentage of CU blocks encoded at each depth of P/B slice as EncCU
diff -r d35b42382331 -r 8e33ade4dac2 source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp Wed Dec 04 22:44:18 2013 -0600
+++ b/source/Lib/TLibEncoder/TEncCu.cpp Thu Dec 05 11:04:22 2013 +0530
@@ -358,7 +358,31 @@
// analysis of CU
if (m_bestCU[0]->getSlice()->getSliceType() == I_SLICE)
+ {
xCompressIntraCU(m_bestCU[0], m_tempCU[0], 0);
+ int i = 0, part;
+ part = m_bestCU[0]->getDepth(i);
+ do
+ {
+ m_log->TotalCu++;
+ int next = m_bestCU[0]->getTotalNumPart() >> (part * 2);
+ if (part == g_maxCUDepth - 1 && m_bestCU[0]->getPartitionSize(i) != SIZE_2Nx2N)
+ {
+ m_log->cntIntraNxN++;
+ }
+ else
+ {
+ m_log->cntIntra[part]++;
+ if (m_bestCU[0]->getLumaIntraDir()[i] > 1)
+ m_log->cuIntraDistribution[part][ANGULAR_MODE_ID]++;
+ else
+ m_log->cuIntraDistribution[part][m_bestCU[0]->getLumaIntraDir()[i]]++;
+ }
+ i += next;
+ part = m_bestCU[0]->getDepth(i);
+ }
+ while (part < g_maxCUDepth);
+ }
else
{
if (m_cfg->param.rdLevel < 5)
@@ -371,6 +395,47 @@
}
else
xCompressCU(m_bestCU[0], m_tempCU[0], 0);
+ int i = 0, part;
+ part = cu->getDepth(i);
+ do
+ {
+ m_log->cntTotalCu[part]++;
+ int next = m_bestCU[0]->getTotalNumPart() >> (part * 2);
+ if (cu->isSkipped(i))
+ {
+ m_log->cntSkipCu[part]++;
+ }
+ else
+ {
+ m_log->TotalCu++;
+ if (cu->getPredictionMode(0) == MODE_INTER)
+ {
+ m_log->cntInter[part]++;
+ if (cu->getPartitionSize(0) < AMP_ID)
+ m_log->cuInterDistribution[part][cu->getPartitionSize(0)]++;
+ else
+ m_log->cuInterDistribution[part][AMP_ID]++;
+ }
+ else if (cu->getPredictionMode(0) == MODE_INTRA)
+ {
+ if (part == g_maxCUDepth - 1 && cu->getPartitionSize(0) == SIZE_NxN)
+ {
+ m_log->cntIntraNxN++;
+ }
+ else
+ {
+ m_log->cntIntra[part]++;
+ if (cu->getLumaIntraDir()[0] > 1)
+ m_log->cuIntraDistribution[part][ANGULAR_MODE_ID]++;
+ else
+ m_log->cuIntraDistribution[part][cu->getLumaIntraDir()[0]]++;
+ }
+ }
+ }
+ i = i + next;
+ part = cu->getDepth(i);
+ }
+ while (part < g_maxCUDepth);
}
}
@@ -467,8 +532,6 @@
{
//PPAScopeEvent(TEncCu_xCompressIntraCU + depth);
- m_log->cntTotalCu[depth]++;
- int boundaryCu = 0;
m_abortFlag = false;
TComPic* pic = outBestCU->getPic();
@@ -535,14 +598,9 @@
// Early CU determination
if (outBestCU->isSkipped(0))
- {
- m_log->cntSkipCu[depth]++;
bSubBranch = false;
- }
else
- {
bSubBranch = true;
- }
}
else if (!(bSliceEnd && bInsidePicture))
{
@@ -575,25 +633,14 @@
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)
{
subBestPartCU[partUnitIdx]->copyToPic(nextDepth);
outTempCU->copyPartFrom(subBestPartCU[partUnitIdx], partUnitIdx, nextDepth);
- boundaryCu++;
}
}
@@ -633,30 +680,9 @@
}
m_rdSbacCoders[nextDepth][CI_NEXT_BEST]->store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
- if (outBestCU->m_totalCost < outTempCU->m_totalCost)
- {
- m_log->cntIntra[depth]++;
- for (int i = 0; i < 4; i++)
- {
- if (outTempCU->getPartitionSize(i) != SIZE_NxN)
- m_log->cntIntra[depth + 1]--;
- 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
@@ -675,7 +701,6 @@
{
//PPAScopeEvent(TEncCu_xCompressCU + depth);
- m_log->cntTotalCu[depth]++;
TComPic* pic = outBestCU->getPic();
m_abortFlag = false;
@@ -923,14 +948,9 @@
// Early CU determination
if (outBestCU->isSkipped(0))
- {
- m_log->cntSkipCu[depth]++;
bSubBranch = false;
- }
else
- {
bSubBranch = true;
- }
}
else if (!(bSliceEnd && bInsidePicture))
{
@@ -971,16 +991,7 @@
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))
- {
- xCompressCU(subBestPartCU, subTempPartCU, nextDepth);
- }
- else
- {
- xCompressCU(subBestPartCU, subTempPartCU, nextDepth);
- }
-
+ xCompressCU(subBestPartCU, subTempPartCU, nextDepth);
outTempCU->copyPartFrom(subBestPartCU, partUnitIdx, nextDepth); // Keep best part data to current temporary data.
xCopyYuv2Tmp(subBestPartCU->getTotalNumPart() * partUnitIdx, nextDepth);
}
@@ -1028,76 +1039,8 @@
}
m_rdSbacCoders[nextDepth][CI_NEXT_BEST]->store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
- if (outBestCU->m_totalCost < outTempCU->m_totalCost)
- {
- if (outBestCU->getPredictionMode(0) == MODE_INTER)
- {
- m_log->cntInter[depth]++;
- if (outBestCU->getPartitionSize(0) < AMP_ID)
- {
- m_log->cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
- }
- else
- {
- m_log->cuInterDistribution[depth][AMP_ID]++;
- }
- }
- else if (outBestCU->getPredictionMode(0) == MODE_INTRA)
- {
- m_log->cntIntra[depth]++;
- if (outBestCU->getLumaIntraDir()[0] > 1)
- {
- m_log->cuIntraDistribution[depth][ANGULAR_MODE_ID]++;
- }
- else
- {
- m_log->cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
- }
- }
- }
- else
- {
- m_log->cntSplit[depth]++;
- }
xCheckBestMode(outBestCU, outTempCU, depth); // RD compare current CU against split
}
- if (depth == g_maxCUDepth - 1)
- {
- if (!outBestCU->isSkipped(0))
- {
- if (outBestCU->getPredictionMode(0) == MODE_INTER)
- {
- m_log->cntInter[depth]++;
- if (outBestCU->getPartitionSize(0) < AMP_ID)
- {
- m_log->cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
- }
- else
- {
- m_log->cuInterDistribution[depth][AMP_ID]++;
- }
- }
- else if (outBestCU->getPredictionMode(0) == MODE_INTRA)
- {
- m_log->cntIntra[depth]++;
- if (outBestCU->getPartitionSize(0) == SIZE_2Nx2N)
- {
- if (outBestCU->getLumaIntraDir()[0] > 1)
- {
- m_log->cuIntraDistribution[depth][ANGULAR_MODE_ID]++;
- }
- else
- {
- m_log->cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
- }
- }
- else if (outBestCU->getPartitionSize(0) == SIZE_NxN)
- {
- m_log->cntIntraNxN++;
- }
- }
- }
- }
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 d35b42382331 -r 8e33ade4dac2 source/Lib/TLibEncoder/TEncCu.h
--- a/source/Lib/TLibEncoder/TEncCu.h Wed Dec 04 22:44:18 2013 -0600
+++ b/source/Lib/TLibEncoder/TEncCu.h Thu Dec 05 11:04:22 2013 +0530
@@ -60,12 +60,12 @@
{
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];
+ uint64_t TotalCu;
StatisticLog()
{
diff -r d35b42382331 -r 8e33ade4dac2 source/encoder/compress.cpp
--- a/source/encoder/compress.cpp Wed Dec 04 22:44:18 2013 -0600
+++ b/source/encoder/compress.cpp Thu Dec 05 11:04:22 2013 +0530
@@ -407,7 +407,6 @@
if (!(depth < minDepth)) //topskip
#endif
{
- m_log->cntTotalCu[depth]++;
if (!bSliceEnd && bInsidePicture)
{
// variables for fast encoder decision
@@ -541,14 +540,9 @@
/* Disable recursive analysis for whole CUs temporarily */
if ((outBestCU != 0) && (outBestCU->isSkipped(0)))
- {
- m_log->cntSkipCu[depth]++;
bSubBranch = false;
- }
else
- {
bSubBranch = true;
- }
m_entropyCoder->resetBits();
m_entropyCoder->encodeSplitFlag(outBestCU, 0, depth, true);
@@ -623,7 +617,6 @@
/* Copy Yuv data to picture Yuv */
xCopyYuv2Pic(outBestCU->getPic(), outBestCU->getAddr(), outBestCU->getZorderIdxInCU(), depth, depth, outBestCU, lpelx, tpely);
- m_log->cntTotalCu[depth]--;
return;
}
}
@@ -708,41 +701,6 @@
m_rdSbacCoders[nextDepth][CI_NEXT_BEST]->store(m_rdSbacCoders[depth][CI_TEMP_BEST]);
- if (outBestCU != 0)
- {
- if (outBestCU->m_totalCost < outTempCU->m_totalCost)
- {
- if (outBestCU->getPredictionMode(0) == MODE_INTER)
- {
- m_log->cntInter[depth]++;
- if (outBestCU->getPartitionSize(0) < AMP_ID)
- {
- m_log->cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
- }
- else
- {
- m_log->cuInterDistribution[depth][AMP_ID]++;
- }
- }
- else if (outBestCU->getPredictionMode(0) == MODE_INTRA)
- {
- m_log->cntIntra[depth]++;
- if (outBestCU->getLumaIntraDir()[0] > 1)
- {
- m_log->cuIntraDistribution[depth][ANGULAR_MODE_ID]++;
- }
- else
- {
- m_log->cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
- }
- }
- }
- else
- {
- m_log->cntSplit[depth]++;
- }
- }
-
/* 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 */
if (outBestCU)
@@ -774,43 +732,6 @@
}
}
- if (depth == g_maxCUDepth - 1)
- {
- if (!outBestCU->isSkipped(0))
- {
- if (outBestCU->getPredictionMode(0) == MODE_INTER)
- {
- m_log->cntInter[depth]++;
- if (outBestCU->getPartitionSize(0) < AMP_ID)
- {
- m_log->cuInterDistribution[depth][outBestCU->getPartitionSize(0)]++;
- }
- else
- {
- m_log->cuInterDistribution[depth][AMP_ID]++;
- }
- }
- else if (outBestCU->getPredictionMode(0) == MODE_INTRA)
- {
- m_log->cntIntra[depth]++;
- if (outBestCU->getPartitionSize(0) == SIZE_2Nx2N)
- {
- if (outBestCU->getLumaIntraDir()[0] > 1)
- {
- m_log->cuIntraDistribution[depth][ANGULAR_MODE_ID]++;
- }
- else
- {
- m_log->cuIntraDistribution[depth][outBestCU->getLumaIntraDir()[0]]++;
- }
- }
- else if (outBestCU->getPartitionSize(0) == SIZE_NxN)
- {
- m_log->cntIntraNxN++;
- }
- }
- }
- }
/* Copy Best data to Picture for next partition prediction. */
outBestCU->copyToPic((UChar)depth);
@@ -818,11 +739,7 @@
/* Copy Yuv data to picture Yuv */
xCopyYuv2Pic(outBestCU->getPic(), outBestCU->getAddr(), outBestCU->getZorderIdxInCU(), depth, depth, outBestCU, lpelx, tpely);
- if (bBoundary || (bSliceEnd && bInsidePicture))
- {
- m_log->cntTotalCu[depth]--;
- return;
- }
+ if (bBoundary || (bSliceEnd && bInsidePicture)) return;
/* Assert if Best prediction mode is NONE
Selected mode's RD-cost must be not MAX_DOUBLE.*/
diff -r d35b42382331 -r 8e33ade4dac2 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Wed Dec 04 22:44:18 2013 -0600
+++ b/source/encoder/encoder.cpp Thu Dec 05 11:04:22 2013 +0530
@@ -392,34 +392,34 @@
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, cntSkipCu, cntIntra, cntIntraNxN, encCu;
uint64_t cuInterDistribution[INTER_MODES], cuIntraDistribution[INTRA_MODES];
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];
+ if (depth == 0)
+ finalLog.TotalCu += enclog.TotalCu;
finalLog.cntIntra[depth] += enclog.cntIntra[depth];
- finalLog.cntTotalCu[depth] += enclog.cntTotalCu[depth];
- if (sliceType != I_SLICE)
+ for (int m = 0; m < INTER_MODES; m++)
{
- 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)
{
- 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;
+ if (sliceType != I_SLICE)
+ {
+ finalLog.cntTotalCu[depth] += enclog.cntTotalCu[depth];
+ finalLog.cntInter[depth] += enclog.cntInter[depth];
+ finalLog.cntSkipCu[depth] += enclog.cntSkipCu[depth];
+ }
}
}
@@ -445,31 +445,44 @@
}
}
- if (finalLog.cntTotalCu[depth] == 0)
+ if (finalLog.TotalCu == 0)
{
- cntInter = 0;
- cntIntra[depth] = 0;
- cntSplit = 0;
- cntSkipCu = 0;
+ encCu = 0;
}
else
{
- cntInter = (finalLog.cntInter[depth] * 100) / finalLog.cntTotalCu[depth];
- cntIntra[depth] = (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];
+ {
+ cntIntra = (finalLog.cntIntra[depth] * 100) / finalLog.TotalCu;
+ cntIntraNxN = (finalLog.cntIntraNxN * 100) / finalLog.TotalCu;
+ }
+ else
+ {
+ encCu = ((finalLog.cntIntra[depth] + finalLog.cntInter[depth]) * 100) / finalLog.TotalCu;
+ }
+ }
+ if (sliceType != I_SLICE)
+ {
+ if (finalLog.cntTotalCu[depth] == 0)
+ {
+ cntInter = 0;
+ cntIntra = 0;
+ cntSkipCu = 0;
+ }
+ else
+ {
+ cntInter = (finalLog.cntInter[depth] * 100) / finalLog.cntTotalCu[depth];
+ cntIntra = (finalLog.cntIntra[depth] * 100) / finalLog.cntTotalCu[depth];
+ cntSkipCu = (finalLog.cntSkipCu[depth] * 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);
+ len += sprintf(stats + len, "EncCU "LL"%% Merge "LL"%% Inter "LL"%%", encCu, cntSkipCu, cntInter);
if (param.bEnableAMP)
len += sprintf(stats + len, "(%dx%d "LL "%% %dx%d "LL "%% %dx%d "LL "%% AMP "LL "%%)",
@@ -482,31 +495,27 @@
cuSize, cuSize, cuInterDistribution[0],
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(¶m, 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(¶m, X265_LOG_INFO, "I-frame %d..4: %s\n", g_maxCUWidth, stats);
+ if (stats[0])
+ x265_log(¶m, X265_LOG_INFO, "%c%-2d: %s\n", sliceType == P_SLICE ? 'P' : sliceType == B_SLICE ? 'B' : 'I', cuSize, stats);
}
}
More information about the x265-devel
mailing list