[x265] [PATCH] stats: add x265_frame_stats structure and copy frame level data to it

Divya Manivannan divya at multicorewareinc.com
Wed Jun 10 15:29:24 CEST 2015


# HG changeset patch
# User Divya Manivannan <divya at multicorewareinc.com>
# Date 1433942708 -19800
#      Wed Jun 10 18:55:08 2015 +0530
# Node ID 35d767d2ac378854794ff36b82a121a2833454f7
# Parent  1225ccb9f8ae9dbc58379e01072a1c3f55cacb61
stats: add x265_frame_stats structure and copy frame level data to it

diff -r 1225ccb9f8ae -r 35d767d2ac37 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Wed Jun 10 18:44:52 2015 +0530
+++ b/source/encoder/encoder.cpp	Wed Jun 10 18:55:08 2015 +0530
@@ -39,8 +39,8 @@
 
 #include "x265.h"
 
-#if _MSC_VER
-#pragma warning (disable: 4996) // POSIX functions are just fine, thanks
+#if _MSC_VER
+#pragma warning (disable: 4996) // POSIX functions are just fine, thanks
 #endif
 
 namespace X265_NS {
@@ -534,6 +534,7 @@
         if (outFrame)
         {
             Slice *slice = outFrame->m_encData->m_slice;
+            x265_frame_stats* frameData = NULL;
 
             /* Free up pic_in->analysisData since it has already been used */
             if (m_param->analysisMode == X265_ANALYSIS_LOAD)
@@ -546,6 +547,7 @@
                 pic_out->bitDepth = X265_DEPTH;
                 pic_out->userData = outFrame->m_userData;
                 pic_out->colorSpace = m_param->internalCsp;
+                frameData = &(pic_out->frameData);
 
                 pic_out->pts = outFrame->m_pts;
                 pic_out->dts = outFrame->m_dts;
@@ -612,7 +614,7 @@
             if (m_aborted)
                 return -1;
 
-            finishFrameStats(outFrame, curEncoder, curEncoder->m_accessUnitBits);
+            finishFrameStats(outFrame, curEncoder, curEncoder->m_accessUnitBits, frameData);
 
             /* Allow this frame to be recycled if no frame encoders are using it for reference */
             if (!pic_out)
@@ -1067,7 +1069,7 @@
     return string;
 }
 
-void Encoder::finishFrameStats(Frame* curFrame, FrameEncoder *curEncoder, uint64_t bits)
+void Encoder::finishFrameStats(Frame* curFrame, FrameEncoder *curEncoder, uint64_t bits, x265_frame_stats* frameStats)
 {
     PicYuv* reconPic = curFrame->m_reconPic;
 
@@ -1138,6 +1140,55 @@
     if (!IS_REFERENCED(curFrame))
         c += 32; // lower case if unreferenced
 
+    if (frameStats)
+    {
+        frameStats->encoderOrder = m_outputCount++;
+        frameStats->sliceType = c;
+        frameStats->poc = poc;
+        frameStats->qp = curEncData.m_avgQpAq;
+        frameStats->bits = bits;
+        if (m_param->rc.rateControlMode == X265_RC_CRF)
+            frameStats->rateFactor = curEncData.m_rateFactor;
+        frameStats->psnrY = psnrY;
+        frameStats->psnrU = psnrU;
+        frameStats->psnrV = psnrV;
+        double psnr = (psnrY * 6 + psnrU + psnrV) / 8;
+        frameStats->psnr = psnr;
+        frameStats->ssim = ssim;
+        if (!slice->isIntra())
+        {
+            int p = 0;
+            for (int ref = 0; ref < slice->m_numRefIdx[0]; ref++)
+            {
+                int k = slice->m_refPOCList[0][ref] - slice->m_lastIDR;
+                p += sprintf(frameStats->list1Buf + p, "%d ", k);
+            }
+            if (!slice->isInterP())
+            {
+                int p1 = 0;
+                for (int ref = 0; ref < slice->m_numRefIdx[1]; ref++)
+                {
+                    int k = slice->m_refPOCList[1][ref] - slice->m_lastIDR;
+                    p1 += sprintf(frameStats->list2Buf + p1, "%d ", k);
+                }
+            }
+        }
+
+#define ELAPSED_MSEC(start, end) (((double)(end) - (start)) / 1000)
+
+        frameStats->decideWaitTime = ELAPSED_MSEC(0, curEncoder->m_slicetypeWaitTime);
+        frameStats->row0WaitTime = ELAPSED_MSEC(curEncoder->m_startCompressTime, curEncoder->m_row0WaitTime);
+        frameStats->wallTime = ELAPSED_MSEC(curEncoder->m_row0WaitTime, curEncoder->m_endCompressTime);
+        frameStats->refWaitWallTime = ELAPSED_MSEC(curEncoder->m_row0WaitTime, curEncoder->m_allRowsAvailableTime);
+        frameStats->totalCTUTime = ELAPSED_MSEC(0, curEncoder->m_totalWorkerElapsedTime);
+        frameStats->stallTime = ELAPSED_MSEC(0, curEncoder->m_totalNoWorkerTime);
+        if (curEncoder->m_totalActiveWorkerCount)
+            frameStats->avgWPP = (double)curEncoder->m_totalActiveWorkerCount / curEncoder->m_activeWorkerCountSamples;
+        else
+            frameStats->avgWPP = 1;
+        frameStats->countRowBlocks = curEncoder->m_countRowBlocks;
+    }
+
     // if debug log level is enabled, per frame console logging is performed
     if (m_param->logLevel >= X265_LOG_DEBUG)
     {
diff -r 1225ccb9f8ae -r 35d767d2ac37 source/encoder/encoder.h
--- a/source/encoder/encoder.h	Wed Jun 10 18:44:52 2015 +0530
+++ b/source/encoder/encoder.h	Wed Jun 10 18:55:08 2015 +0530
@@ -166,7 +166,7 @@
 
     void writeAnalysisFile(x265_analysis_data* pic);
 
-    void finishFrameStats(Frame* pic, FrameEncoder *curEncoder, uint64_t bits);
+    void finishFrameStats(Frame* pic, FrameEncoder *curEncoder, uint64_t bits, x265_frame_stats* frameStats);
 
 protected:
 
diff -r 1225ccb9f8ae -r 35d767d2ac37 source/x265.cpp
--- a/source/x265.cpp	Wed Jun 10 18:44:52 2015 +0530
+++ b/source/x265.cpp	Wed Jun 10 18:55:08 2015 +0530
@@ -634,7 +634,7 @@
     x265_picture *pic_in = &pic_orig;
     /* Allocate recon picture if analysisMode is enabled */
     std::priority_queue<int64_t>* pts_queue = cliopt.output->needPTS() ? new std::priority_queue<int64_t>() : NULL;
-    x265_picture *pic_recon = (cliopt.recon || !!param->analysisMode || pts_queue || reconPlay) ? &pic_out : NULL;
+    x265_picture *pic_recon = (cliopt.recon || !!param->analysisMode || pts_queue || reconPlay || cliopt.csvData > 0) ? &pic_out : NULL;
     uint32_t inFrameCount = 0;
     uint32_t outFrameCount = 0;
     x265_nal *p_nal;
diff -r 1225ccb9f8ae -r 35d767d2ac37 source/x265.h
--- a/source/x265.h	Wed Jun 10 18:44:52 2015 +0530
+++ b/source/x265.h	Wed Jun 10 18:55:08 2015 +0530
@@ -100,6 +100,32 @@
     uint32_t         numPartitions;
 } x265_analysis_data;
 
+/* Frame level statistics*/
+typedef struct x265_frame_stats
+{
+    double           qp;
+    double           rateFactor;
+    double           psnrY;
+    double           psnrU;
+    double           psnrV;
+    double           psnr;
+    double           ssim;
+    double           decideWaitTime;
+    double           row0WaitTime;
+    double           wallTime;
+    double           refWaitWallTime;
+    double           totalCTUTime;
+    double           stallTime;
+    double           avgWPP;
+    uint64_t         bits;
+    int              encoderOrder;
+    int              poc;
+    int              countRowBlocks;
+    char             list1Buf[16];
+    char             list2Buf[16];
+    char             sliceType;
+} x265_frame_stats;
+
 /* Used to pass pictures into the encoder, and to get picture data back out of
  * the encoder.  The input and output semantics are different */
 typedef struct x265_picture
@@ -161,6 +187,9 @@
      * this data structure */
     x265_analysis_data analysisData;
 
+    /* Frame level statistics*/
+    x265_frame_stats frameData;
+
 } x265_picture;
 
 typedef enum


More information about the x265-devel mailing list