[x265] [PATCH] Added x265_stats_t structure and x265_encoder_stats API to fetch output stats from encoder

Aarthi Thirumalai aarthi at multicorewareinc.com
Tue Oct 1 13:59:23 CEST 2013


# HG changeset patch
# User Aarthi Thirumalai
# Date 1380628699 -19800
#      Tue Oct 01 17:28:19 2013 +0530
# Node ID fc225ea42650867a229d15f41e1f2a495629bb7d
# Parent  36e2f4978ae40b23efa1a5403d59168d551f29a6
Added x265_stats_t structure and x265_encoder_stats API to fetch output stats from encoder

diff -r 36e2f4978ae4 -r fc225ea42650 source/Lib/TLibEncoder/TEncTop.cpp
--- a/source/Lib/TLibEncoder/TEncTop.cpp	Tue Oct 01 15:09:55 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncTop.cpp	Tue Oct 01 17:28:19 2013 +0530
@@ -312,6 +312,19 @@
         return 100.0;
 }
 
+void TEncTop::fetchStats(x265_stats_t *stats)
+{
+    stats->globalPsnrY = m_analyzeAll.getPsnrY();
+    stats->globalPsnrU = m_analyzeAll.getPsnrU();
+    stats->globalPsnrV = m_analyzeAll.getPsnrV();
+    stats->totalNumPics = m_analyzeAll.getNumPic();
+    stats->accBits = m_analyzeAll.getBits();
+    if (stats->totalNumPics > 0)
+        stats->globalSsim = m_globalSsim / stats->totalNumPics;
+    else
+        stats->globalSsim = 0;
+}
+
 #define VERBOSE_RATE 0
 #if VERBOSE_RATE
 static const char* nalUnitTypeToString(NalUnitType type)
diff -r 36e2f4978ae4 -r fc225ea42650 source/Lib/TLibEncoder/TEncTop.h
--- a/source/Lib/TLibEncoder/TEncTop.h	Tue Oct 01 15:09:55 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncTop.h	Tue Oct 01 17:28:19 2013 +0530
@@ -106,6 +106,8 @@
 
     int getStreamHeaders(NALUnitEBSP **nalunits);
 
+    void fetchStats(x265_stats_t* stats);
+
     double printSummary();
 
     TComScalingList* getScalingList() { return &m_scalingList; }
diff -r 36e2f4978ae4 -r fc225ea42650 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Tue Oct 01 15:09:55 2013 +0530
+++ b/source/encoder/encoder.cpp	Tue Oct 01 17:28:19 2013 +0530
@@ -429,6 +429,15 @@
 EXTERN_CYCLE_COUNTER(ME);
 
 extern "C"
+void x265_encoder_stats(x265_t *encoder, x265_stats_t *outputStats)
+{
+    CHECKED_MALLOC(outputStats, x265_stats_t, 1);
+    encoder->fetchStats(outputStats);
+fail:
+    return;
+}
+
+extern "C"
 void x265_encoder_close(x265_t *encoder, double *outPsnr)
 {
     double globalPsnr = encoder->printSummary();
diff -r 36e2f4978ae4 -r fc225ea42650 source/x265.cpp
--- a/source/x265.cpp	Tue Oct 01 15:09:55 2013 +0530
+++ b/source/x265.cpp	Tue Oct 01 17:28:19 2013 +0530
@@ -511,6 +511,7 @@
     x265_picture_t *pic_in = &pic_orig;
     x265_picture_t *pic_recon = cliopt.recon ? &pic_out : NULL;
     x265_nal_t *p_nal;
+    x265_stats_t *stats = NULL;
     int nal;
 
     if (!x265_encoder_headers(encoder, &p_nal, &nal))
@@ -571,6 +572,7 @@
         fprintf(stderr, "                                                                               \r");
 
     double PSNR = 0.0;
+    x265_encoder_stats(encoder, stats);
     x265_encoder_close(encoder, &PSNR);
     cliopt.bitstreamFile.close();
 
@@ -580,8 +582,14 @@
     double elapsed = (double)(x265_mdate() - cliopt.i_start) / 1000000;
     double vidtime = (double)inFrameCount / param.frameRate;
     double bitrate = (0.008f * cliopt.totalBytes) / vidtime;
-    printf("\nencoded %d frames in %.2fs (%.2f fps), %.2f kb/s, Global PSNR: %.3f\n",
-           outFrameCount, elapsed, outFrameCount / elapsed, bitrate, PSNR);
+    printf("\nencoded %d frames in %.2fs (%.2f fps), %.2f kb/s, ",
+           outFrameCount, elapsed, outFrameCount / elapsed, bitrate);
+
+    if (param.bEnablePsnr)
+        printf("Global PSNR: %.3f\n", PSNR);
+
+    if (param.bEnableSsim && stats)
+        printf("Global SSIM: %.3f\n", stats->globalSsim);
 
     x265_cleanup(); /* Free library singletons */
 
diff -r 36e2f4978ae4 -r fc225ea42650 source/x265.h
--- a/source/x265.h	Tue Oct 01 15:09:55 2013 +0530
+++ b/source/x265.h	Tue Oct 01 17:28:19 2013 +0530
@@ -192,7 +192,20 @@
 }
 X265_RDO_LEVEL;
 
+/* Output Stats from encoder */
+typedef struct x265_stats_t
+{
+    double    globalPsnrY;
+    double    globalPsnrU;
+    double    globalPsnrV;
+    double    globalSsim;
+    double    accBits;
+    double    totalNumPics;
 
+}
+x265_stats_t;
+
+/* Input parameters to the encoder */
 typedef struct x265_param_t
 {
     int       logLevel;
@@ -344,6 +357,10 @@
  *      the payloads of all output NALs are guaranteed to be sequential in memory. */
 int     x265_encoder_encode(x265_t *encoder, x265_nal_t **pp_nal, int *pi_nal, x265_picture_t *pic_in, x265_picture_t *pic_out);
 
+/* x265_encoder_stats:
+*       returns output stats from the encoder */
+void    x265_encoder_stats(x265_t *encoder, x265_stats_t *);
+
 /* x265_encoder_close:
  *      close an encoder handler.  Optionally return the global PSNR value (6 * psnrY + psnrU + psnrV) / 8 */
 void    x265_encoder_close(x265_t *, double *globalPsnr);


More information about the x265-devel mailing list