x264中的PSNR计算及其打印

2010-01-22 21:39
x264在设置参数后,如果不进行psnr的设置,在编译的时候是不会打印出来信噪比的信息的,这里,只要在参数里面进行设置一下,如:--psnr,就可以打印出YUV的峰值信噪比的信息来,这里就把,在程序中的信噪比的计算和相关函数在这里列举出来:
1.这里是先定义求解信噪比的函数:
static float x264_psnr( int64_t i_sqe, int64_t i_size )
{
double f_mse = (double)i_sqe / ((double)65025.0 * (double)i_size);
if( f_mse <= 0.0000000001 ) /* Max 100dB */
return 100;

return (float)(-10.0 * log( f_mse ) / log( 10.0 ));
}

2.函数的调用:
if( h->param.analyse.b_psnr )
{
int64_t ssd[3] = {
h->stat.frame.i_ssd[0],
h->stat.frame.i_ssd[1],
h->stat.frame.i_ssd[2],
};

h->stat.i_ssd_global[h->sh.i_type] += ssd[0] + ssd[1] + ssd[2];
h->stat.f_psnr_average[h->sh.i_type] += x264_psnr( ssd[0] + ssd[1] + ssd[2], 3 * h->param.i_width * h->param.i_height / 2 );
h->stat.f_psnr_mean_y[h->sh.i_type] += x264_psnr( ssd[0], h->param.i_width * h->param.i_height );
h->stat.f_psnr_mean_u[h->sh.i_type] += x264_psnr( ssd[1], h->param.i_width * h->param.i_height / 4 );
h->stat.f_psnr_mean_v[h->sh.i_type] += x264_psnr( ssd[2], h->param.i_width * h->param.i_height / 4 );

snprintf( psz_message, 80, " PSNR Y:%5.2f U:%5.2f V:%5.2f",
x264_psnr( ssd[0], h->param.i_width * h->param.i_height ),
x264_psnr( ssd[1], h->param.i_width * h->param.i_height / 4),
x264_psnr( ssd[2], h->param.i_width * h->param.i_height / 4) );
}
......................................................................................
if( h->param.analyse.b_psnr )
{
x264_log( h, X264_LOG_INFO,
"slice %s:%-5d Avg QP:%5.2f  size:%6.0f  PSNR Mean Y:%5.2f U:%5.2f V:%5.2f Avg:%5.2f Global:%5.2f\n",
slice_name[i_slice],
i_count,
h->stat.f_slice_qp[i_slice] / i_count,
(double)h->stat.i_slice_size[i_slice] / i_count,
h->stat.f_psnr_mean_y[i_slice] / i_count, h->stat.f_psnr_mean_u[i_slice] / i_count, h->stat.f_psnr_mean_v[i_slice] / i_count,
h->stat.f_psnr_average[i_slice] / i_count,
x264_psnr( h->stat.i_ssd_global[i_slice], i_count * i_yuv_size ) );
}

..........................................................
if( h->param.analyse.b_psnr )
{
x264_log( h, X264_LOG_INFO,
"PSNR Mean Y:%6.3f U:%6.3f V:%6.3f Avg:%6.3f Global:%6.3f kb/s:%.2f\n",
SUM3( h->stat.f_psnr_mean_y ) / i_count,
SUM3( h->stat.f_psnr_mean_u ) / i_count,
SUM3( h->stat.f_psnr_mean_v ) / i_count,
SUM3( h->stat.f_psnr_average ) / i_count,
x264_psnr( SUM3( h->stat.i_ssd_global ), i_count * i_yuv_size ),
f_bitrate );
}
else
x264_log( h, X264_LOG_INFO, "kb/s:%.1f\n", f_bitrate );

这里还有一部分变量的定义,基本完成了这些内容!

你可能感兴趣的:(x264中的PSNR计算及其打印)