[x265] [PATCH] rc: write frame stats and cu stats to file in first pass

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Mon Jun 30 18:38:36 CEST 2014


# HG changeset patch
# User Aarthi Thirumalai<aarthi at multicorewareinc.com>
# Date 1404146150 -19800
#      Mon Jun 30 22:05:50 2014 +0530
# Node ID b4f9deb0a7c1f3279f519feac7fedb41139c1435
# Parent  2dd5aded9e192783dfc8f8307a05e3b2a55b7f1d
rc: write frame stats and cu stats to file in first pass

diff -r 2dd5aded9e19 -r b4f9deb0a7c1 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Jun 26 17:49:26 2014 +0530
+++ b/source/encoder/encoder.cpp	Mon Jun 30 22:05:50 2014 +0530
@@ -408,7 +408,12 @@
                 bytes -= (!i || type == NAL_UNIT_SPS || type == NAL_UNIT_PPS) ? 4 : 3;
             }
         }
-        m_rateControl->rateControlEnd(out, bytes << 3, &curEncoder->m_rce);
+        if (m_rateControl->rateControlEnd(out, bytes << 3, &curEncoder->m_rce) < 0)
+        {
+            x265_log(m_param, X265_LOG_ERROR, "RatecontrolEnd: stats file could not be written to\n" );
+            m_aborted = true;
+            return -1;
+        }
         finishFrameStats(out, curEncoder, bytes << 3);
 
         // Allow this frame to be recycled if no frame encoders are using it for reference
@@ -445,8 +450,8 @@
                 fenc->getPicSym()->allocSaoParam(m_frameEncoder->getSAO());
         }
         fenc->getSlice()->setPOC(fenc->m_POC);
+        curEncoder->m_rce.encodeOrder = m_encodedFrameNum++;
 
-        m_encodedFrameNum++;
         if (m_bframeDelay)
         {
             int64_t *prevReorderedPts = m_prevReorderedPts;
diff -r 2dd5aded9e19 -r b4f9deb0a7c1 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Thu Jun 26 17:49:26 2014 +0530
+++ b/source/encoder/ratecontrol.cpp	Mon Jun 30 22:05:50 2014 +0530
@@ -1274,6 +1274,38 @@
                 }
             }
 
+            // 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 ? 'I' : 'i')
+                            : rce->sliceType == P_SLICE ? (pic->getSlice()->isReferenced()? 'P' : 'p')
+                            : pic->getSlice()->isReferenced()? 'B' : 'b';
+                if (fprintf(m_statFileOut,
+                         "in:%d out:%d type:%c dur:%.3f q:%.2f q-aq:%.2f tex:%d mv:%d misc:%d imb:%d pmb:%d smb:%d ",
+                         rce->poc, rce->encodeOrder,
+                         cType, m_frameDuration,
+                         pic->m_avgQpRc, pic->m_avgQpAq,
+                         pic->m_stats.coeffBits,
+                         pic->m_stats.mvBits,
+                         pic->m_stats.miscBits,
+                         pic->m_stats.cuCount_i,
+                         pic->m_stats.cuCount_p,
+                         pic->m_stats.cuCount_skip) < 0 )
+                    return -1;
+                if (fprintf(m_statFileOut, ";\n") < 0)
+                    return -1;
+                /* Don't re-write the data in multi-pass mode. */
+                if (m_param->rc.cuTree && pic->getSlice()->isReferenced() && !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)pic->m_lowres.qpCuTreeOffset[i]) * 256.0;
+                    if (fwrite(&sliceType, 1, 1, m_cutreeStatFileOut) < 1)
+                        return -1;
+                    if (fwrite(m_cuTreeStats.qpBuffer[0], sizeof(uint16_t), m_ncu, m_cutreeStatFileOut) < m_ncu)
+                        return -1;
+                }
+            }
             /* amortize part of each I slice over the next several frames, up to
              * keyint-max, to avoid over-compensating for the large I slice cost */
             if (rce->sliceType == I_SLICE)
diff -r 2dd5aded9e19 -r b4f9deb0a7c1 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Thu Jun 26 17:49:26 2014 +0530
+++ b/source/encoder/ratecontrol.h	Mon Jun 30 22:05:50 2014 +0530
@@ -59,6 +59,7 @@
     int mvBits;
     int bframes;
     int poc;
+    uint64_t encodeOrder;
     int64_t leadingNoBSatd;
     bool bLastMiniGopBFrame;
     double blurredComplexity;


More information about the x265-devel mailing list