[x265] [PATCH] rc: fix corrupted stat file issue in multipass encodes (ref #147)
aarthi at multicorewareinc.com
aarthi at multicorewareinc.com
Mon Aug 17 10:47:51 CEST 2015
# HG changeset patch
# User Aarthi Thirumalai
# Date 1439801027 -19800
# Mon Aug 17 14:13:47 2015 +0530
# Node ID 42ae42318a18111e2c76d1882ceb432731f6df7b
# Parent 996ebce8c874fc511d495cee227d24413e99d0c1
rc: fix corrupted stat file issue in multipass encodes (ref #147)
diff -r 996ebce8c874 -r 42ae42318a18 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Mon Aug 17 10:52:15 2015 +0530
+++ b/source/encoder/encoder.cpp Mon Aug 17 14:13:47 2015 +0530
@@ -682,9 +682,13 @@
/* Allow FrameEncoder::compressFrame() to start in the frame encoder thread */
if (!curEncoder->startCompressFrame(frameEnc))
m_aborted = true;
+ /* Write RateControl Frame level stats in multipass encodes */
+ if (m_param->rc.bStatWrite)
+ if (m_rateControl->writeRateControlFrameStats(frameEnc, &curEncoder->m_rce))
+ m_aborted = true;
}
else if (m_encodedFrameNum)
- m_rateControl->setFinalFrameCount(m_encodedFrameNum);
+ m_rateControl->setFinalFrameCount(m_encodedFrameNum);
}
while (m_bZeroLatency && ++pass < 2);
diff -r 996ebce8c874 -r 42ae42318a18 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Mon Aug 17 10:52:15 2015 +0530
+++ b/source/encoder/ratecontrol.cpp Mon Aug 17 14:13:47 2015 +0530
@@ -2196,35 +2196,6 @@
}
}
- // Write frame stats into the stats file if 2 pass is enabled.
- if (m_param->rc.bStatWrite)
- {
- char cType = rce->sliceType == I_SLICE ? (rce->poc > 0 && m_param->bOpenGOP ? 'i' : 'I')
- : rce->sliceType == P_SLICE ? 'P'
- : IS_REFERENCED(curFrame) ? 'B' : 'b';
- if (fprintf(m_statFileOut,
- "in:%d out:%d type:%c q:%.2f q-aq:%.2f tex:%d mv:%d misc:%d icu:%.2f pcu:%.2f scu:%.2f ;\n",
- rce->poc, rce->encodeOrder,
- cType, curEncData.m_avgQpRc, curEncData.m_avgQpAq,
- curFrame->m_encData->m_frameStats.coeffBits,
- curFrame->m_encData->m_frameStats.mvBits,
- curFrame->m_encData->m_frameStats.miscBits,
- curFrame->m_encData->m_frameStats.percent8x8Intra * m_ncu,
- curFrame->m_encData->m_frameStats.percent8x8Inter * m_ncu,
- curFrame->m_encData->m_frameStats.percent8x8Skip * m_ncu) < 0)
- goto writeFailure;
- /* Don't re-write the data in multi-pass mode. */
- if (m_param->rc.cuTree && IS_REFERENCED(curFrame) && !m_param->rc.bStatRead)
- {
- uint8_t sliceType = (uint8_t)rce->sliceType;
- for (int i = 0; i < m_ncu; i++)
- m_cuTreeStats.qpBuffer[0][i] = (uint16_t)(curFrame->m_lowres.qpCuTreeOffset[i] * 256.0);
- if (fwrite(&sliceType, 1, 1, m_cutreeStatFileOut) < 1)
- goto writeFailure;
- if (fwrite(m_cuTreeStats.qpBuffer[0], sizeof(uint16_t), m_ncu, m_cutreeStatFileOut) < (size_t)m_ncu)
- goto writeFailure;
- }
- }
if (m_isAbr && !m_isAbrReset)
{
/* amortize part of each I slice over the next several frames, up to
@@ -2306,12 +2277,43 @@
// Allow rateControlStart of next frame only when rateControlEnd of previous frame is over
m_startEndOrder.incr();
return 0;
+}
-writeFailure:
+/* called to write out the rate control frame stats info in multipass encodes */
+int RateControl::writeRateControlFrameStats(Frame* curFrame, RateControlEntry* rce)
+{
+ FrameData& curEncData = *curFrame->m_encData;
+ char cType = rce->sliceType == I_SLICE ? (rce->poc > 0 && m_param->bOpenGOP ? 'i' : 'I')
+ : rce->sliceType == P_SLICE ? 'P'
+ : IS_REFERENCED(curFrame) ? 'B' : 'b';
+ if (fprintf(m_statFileOut,
+ "in:%d out:%d type:%c q:%.2f q-aq:%.2f tex:%d mv:%d misc:%d icu:%.2f pcu:%.2f scu:%.2f ;\n",
+ rce->poc, rce->encodeOrder,
+ cType, curEncData.m_avgQpRc, curEncData.m_avgQpAq,
+ curFrame->m_encData->m_frameStats.coeffBits,
+ curFrame->m_encData->m_frameStats.mvBits,
+ curFrame->m_encData->m_frameStats.miscBits,
+ curFrame->m_encData->m_frameStats.percent8x8Intra * m_ncu,
+ curFrame->m_encData->m_frameStats.percent8x8Inter * m_ncu,
+ curFrame->m_encData->m_frameStats.percent8x8Skip * m_ncu) < 0)
+ goto writeFailure;
+ /* Don't re-write the data in multi-pass mode. */
+ if (m_param->rc.cuTree && IS_REFERENCED(curFrame) && !m_param->rc.bStatRead)
+ {
+ uint8_t sliceType = (uint8_t)rce->sliceType;
+ for (int i = 0; i < m_ncu; i++)
+ m_cuTreeStats.qpBuffer[0][i] = (uint16_t)(curFrame->m_lowres.qpCuTreeOffset[i] * 256.0);
+ if (fwrite(&sliceType, 1, 1, m_cutreeStatFileOut) < 1)
+ goto writeFailure;
+ if (fwrite(m_cuTreeStats.qpBuffer[0], sizeof(uint16_t), m_ncu, m_cutreeStatFileOut) < (size_t)m_ncu)
+ goto writeFailure;
+ }
+ return 0;
+
+ writeFailure:
x265_log(m_param, X265_LOG_ERROR, "RatecontrolEnd: stats file write failure\n");
return 1;
}
-
#if defined(_MSC_VER)
#pragma warning(disable: 4996) // POSIX function names are just fine, thank you
#endif
diff -r 996ebce8c874 -r 42ae42318a18 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h Mon Aug 17 10:52:15 2015 +0530
+++ b/source/encoder/ratecontrol.h Mon Aug 17 14:13:47 2015 +0530
@@ -229,7 +229,7 @@
int rateControlSliceType(int frameNum);
bool cuTreeReadFor2Pass(Frame* curFrame);
void hrdFullness(SEIBufferingPeriod* sei);
-
+ int writeRateControlFrameStats(Frame* curFrame, RateControlEntry* rce);
protected:
static const int s_slidingWindowFrames;
More information about the x265-devel
mailing list