[x264-devel] Export PSNR/SSIM in x264 API

Jason Garrett-Glaser git at videolan.org
Wed Mar 7 03:20:14 CET 2012


x264 | branch: master | Jason Garrett-Glaser <jason at x264.com> | Mon Feb 13 13:20:06 2012 -0800| [9f1ac3b36eb2666e9d2ec4b859f3b63f60827bf0] | committer: Jason Garrett-Glaser

Export PSNR/SSIM in x264 API

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=9f1ac3b36eb2666e9d2ec4b859f3b63f60827bf0
---

 encoder/encoder.c |   26 ++++++++++++++------------
 x264.h            |   11 +++++++++--
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 4ef933b..f446583 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -3231,26 +3231,28 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
         };
         int luma_size = h->param.i_width * h->param.i_height;
         int chroma_size = CHROMA_SIZE( luma_size );
-        double psnr_y = x264_psnr( ssd[0], luma_size );
-        double psnr_u = x264_psnr( ssd[1], chroma_size );
-        double psnr_v = x264_psnr( ssd[2], chroma_size );
+        pic_out->prop.f_psnr[0] = x264_psnr( ssd[0], luma_size );
+        pic_out->prop.f_psnr[1] = x264_psnr( ssd[1], chroma_size );
+        pic_out->prop.f_psnr[2] = x264_psnr( ssd[2], chroma_size );
+        pic_out->prop.f_psnr_avg = x264_psnr( ssd[0] + ssd[1] + ssd[2], luma_size + chroma_size*2 );
 
         h->stat.f_ssd_global[h->sh.i_type]   += dur * (ssd[0] + ssd[1] + ssd[2]);
-        h->stat.f_psnr_average[h->sh.i_type] += dur * x264_psnr( ssd[0] + ssd[1] + ssd[2], luma_size + chroma_size*2 );
-        h->stat.f_psnr_mean_y[h->sh.i_type]  += dur * psnr_y;
-        h->stat.f_psnr_mean_u[h->sh.i_type]  += dur * psnr_u;
-        h->stat.f_psnr_mean_v[h->sh.i_type]  += dur * psnr_v;
+        h->stat.f_psnr_average[h->sh.i_type] += dur * pic_out->prop.f_psnr_avg;
+        h->stat.f_psnr_mean_y[h->sh.i_type]  += dur * pic_out->prop.f_psnr[0];
+        h->stat.f_psnr_mean_u[h->sh.i_type]  += dur * pic_out->prop.f_psnr[1];
+        h->stat.f_psnr_mean_v[h->sh.i_type]  += dur * pic_out->prop.f_psnr[2];
 
-        snprintf( psz_message, 80, " PSNR Y:%5.2f U:%5.2f V:%5.2f", psnr_y, psnr_u, psnr_v );
+        snprintf( psz_message, 80, " PSNR Y:%5.2f U:%5.2f V:%5.2f", pic_out->prop.f_psnr[0],
+                                                                    pic_out->prop.f_psnr[1],
+                                                                    pic_out->prop.f_psnr[2] );
     }
 
     if( h->param.analyse.b_ssim )
     {
-        double ssim_y = h->stat.frame.f_ssim
-                      / h->stat.frame.i_ssim_cnt;
-        h->stat.f_ssim_mean_y[h->sh.i_type] += ssim_y * dur;
+        pic_out->prop.f_ssim = h->stat.frame.f_ssim / h->stat.frame.i_ssim_cnt;
+        h->stat.f_ssim_mean_y[h->sh.i_type] += pic_out->prop.f_ssim * dur;
         snprintf( psz_message + strlen(psz_message), 80 - strlen(psz_message),
-                  " SSIM Y:%.5f", ssim_y );
+                  " SSIM Y:%.5f", pic_out->prop.f_ssim );
     }
     psz_message[79] = '\0';
 
diff --git a/x264.h b/x264.h
index 322efb4..2a34d01 100644
--- a/x264.h
+++ b/x264.h
@@ -41,7 +41,7 @@
 
 #include "x264_config.h"
 
-#define X264_BUILD 120
+#define X264_BUILD 121
 
 /* x264_t:
  *      opaque handler for encoder */
@@ -689,6 +689,12 @@ typedef struct
     /* In: optional callback to free quant_offsets when used.
      *     Useful if one wants to use a different quant_offset array for each frame. */
     void (*quant_offsets_free)( void* );
+    /* Out: SSIM of the the frame luma (if x264_param_t.b_ssim is set) */
+    double f_ssim;
+    /* Out: Average PSNR of the frame (if x264_param_t.b_psnr is set) */
+    double f_psnr_avg;
+    /* Out: PSNR of Y, U, and V (if x264_param_t.b_psnr is set) */
+    double f_psnr[3];
 } x264_image_properties_t;
 
 typedef struct
@@ -723,7 +729,8 @@ typedef struct
     x264_param_t *param;
     /* In: raw data */
     x264_image_t img;
-    /* In: optional information to modify encoder decisions for this frame */
+    /* In: optional information to modify encoder decisions for this frame
+     * Out: information about the encoded frame */
     x264_image_properties_t prop;
     /* Out: HRD timing information. Output only when i_nal_hrd is set. */
     x264_hrd_t hrd_timing;



More information about the x264-devel mailing list