Export PSNR/SSIM in x264 API
authorFiona Glaser <fiona@x264.com>
Mon, 13 Feb 2012 21:20:06 +0000 (13:20 -0800)
committerFiona Glaser <fiona@x264.com>
Tue, 6 Mar 2012 18:38:05 +0000 (10:38 -0800)
encoder/encoder.c
x264.h

index 8c72ed5..f13e24e 100644 (file)
@@ -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 8dbada8..b5e38d4 100644 (file)
--- 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;