[x265] [PATCH] csv: add buffer fill per frame in csv

Divya Manivannan divya at multicorewareinc.com
Tue Sep 27 09:03:17 CEST 2016


# HG changeset patch
# User Divya Manivannan <divya at multicorewareinc.com>
# Date 1474719617 -19800
#      Sat Sep 24 17:50:17 2016 +0530
# Node ID 9650164ef1a9b985a7882db2c3180b5383dfdde2
# Parent  d20b78d6d138de25040a756e7df10b8c45eabba8
csv: add buffer fill per frame in csv

diff -r d20b78d6d138 -r 9650164ef1a9 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Sep 22 15:54:24 2016 +0530
+++ b/source/encoder/encoder.cpp	Sat Sep 24 17:50:17 2016 +0530
@@ -1353,6 +1353,7 @@
         frameStats->qp = curEncData.m_avgQpAq;
         frameStats->bits = bits;
         frameStats->bScenecut = curFrame->m_lowres.bScenecut;
+        frameStats->bufferFill = m_rateControl->m_bufferFillActual;
         frameStats->frameLatency = inPoc - poc;
         if (m_param->rc.rateControlMode == X265_RC_CRF)
             frameStats->rateFactor = curEncData.m_rateFactor;
diff -r d20b78d6d138 -r 9650164ef1a9 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Thu Sep 22 15:54:24 2016 +0530
+++ b/source/encoder/ratecontrol.cpp	Sat Sep 24 17:50:17 2016 +0530
@@ -341,6 +341,8 @@
             m_param->rc.vbvBufferInit = x265_clip3(0.0, 1.0, m_param->rc.vbvBufferInit / m_param->rc.vbvBufferSize);
         m_param->rc.vbvBufferInit = x265_clip3(0.0, 1.0, X265_MAX(m_param->rc.vbvBufferInit, m_bufferRate / m_bufferSize));
         m_bufferFillFinal = m_bufferSize * m_param->rc.vbvBufferInit;
+        m_bufferFillActual = m_bufferFillFinal;
+        m_bufferExcess = 0;
     }
 
     m_totalBits = 0;
@@ -2446,6 +2448,10 @@
     m_bufferFillFinal = X265_MAX(m_bufferFillFinal, 0);
     m_bufferFillFinal += m_bufferRate;
     m_bufferFillFinal = X265_MIN(m_bufferFillFinal, m_bufferSize);
+    double bufferBits = X265_MIN(bits + m_bufferExcess, m_bufferRate);
+    m_bufferExcess = X265_MAX(m_bufferExcess - bufferBits + bits, 0);
+    m_bufferFillActual += bufferBits - bits;
+    m_bufferFillActual = X265_MIN(m_bufferFillActual, m_bufferSize);
 }
 
 /* After encoding one frame, update rate control state */
diff -r d20b78d6d138 -r 9650164ef1a9 source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h	Thu Sep 22 15:54:24 2016 +0530
+++ b/source/encoder/ratecontrol.h	Sat Sep 24 17:50:17 2016 +0530
@@ -144,6 +144,8 @@
     double m_rateFactorMaxIncrement; /* Don't allow RF above (CRF + this value). */
     double m_rateFactorMaxDecrement; /* don't allow RF below (this value). */
     double m_avgPFrameQp;
+    double m_bufferFillActual;
+    double m_bufferExcess;
     bool   m_isFirstMiniGop;
     Predictor m_pred[4];       /* Slice predictors to preidct bits for each Slice type - I,P,Bref and B */
     int64_t m_leadingNoBSatd;
diff -r d20b78d6d138 -r 9650164ef1a9 source/x265-extras.cpp
--- a/source/x265-extras.cpp	Thu Sep 22 15:54:24 2016 +0530
+++ b/source/x265-extras.cpp	Sat Sep 24 17:50:17 2016 +0530
@@ -64,6 +64,8 @@
                 fprintf(csvfp, "Encode Order, Type, POC, QP, Bits, Scenecut, ");
                 if (param.rc.rateControlMode == X265_RC_CRF)
                     fprintf(csvfp, "RateFactor, ");
+                if (param.rc.vbvBufferSize)
+                    fprintf(csvfp, "BufferFill, ");
                 if (param.bEnablePsnr)
                     fprintf(csvfp, "Y PSNR, U PSNR, V PSNR, YUV PSNR, ");
                 if (param.bEnableSsim)
@@ -132,6 +134,8 @@
     fprintf(csvfp, "%d, %c-SLICE, %4d, %2.2lf, %10d, %d,", frameStats->encoderOrder, frameStats->sliceType, frameStats->poc, frameStats->qp, (int)frameStats->bits, frameStats->bScenecut);
     if (param.rc.rateControlMode == X265_RC_CRF)
         fprintf(csvfp, "%.3lf,", frameStats->rateFactor);
+    if (param.rc.vbvBufferSize)
+        fprintf(csvfp, "%.3lf,", frameStats->bufferFill);
     if (param.bEnablePsnr)
         fprintf(csvfp, "%.3lf, %.3lf, %.3lf, %.3lf,", frameStats->psnrY, frameStats->psnrU, frameStats->psnrV, frameStats->psnr);
     if (param.bEnableSsim)
diff -r d20b78d6d138 -r 9650164ef1a9 source/x265.h
--- a/source/x265.h	Thu Sep 22 15:54:24 2016 +0530
+++ b/source/x265.h	Sat Sep 24 17:50:17 2016 +0530
@@ -137,6 +137,7 @@
     double           avgPsyEnergy;
     double           avgResEnergy;
     double           avgLumaLevel;
+    double           bufferFill;
     uint64_t         bits;
     int              encoderOrder;
     int              poc;


More information about the x265-devel mailing list