x264中tune等级有8个,表示应用的场景。
相比preset,tune主要调节环路滤波强度、psy强度、adaptive qp强度等画质相关因素。
const char * const x264_tune_names[] = {
"film", "animation", "grain",
"stillimage", "psnr", "ssim",
"fastdecode", "zerolatency","touhou", 0 };
film
if( !strncasecmp( s, "film", 4 ) )
{
if( psy_tuning_used++ ) goto psy_failure;
//环路滤波alphac和beta都为-1
param->i_deblocking_filter_alphac0 = -1;
param->i_deblocking_filter_beta = -1;
//trellis量化强度0.15
param->analyse.f_psy_trellis = 0.15;
}
animation
else if( !strncasecmp( s, "animation", 9 ) )
{
if( psy_tuning_used++ ) goto psy_failure;
//参考帧列表帧数>1则double一下
param->i_frame_reference = param->i_frame_reference > 1 ? param->i_frame_reference*2 : 1;
//环路滤波alphac和beta都为1
param->i_deblocking_filter_alphac0 = 1;
param->i_deblocking_filter_beta = 1;
//psy rd强度0.4
param->analyse.f_psy_rd = 0.4;
//adaptive qp强度0.5
param->rc.f_aq_strength = 0.6;
//增加可连续B帧的数量
param->i_bframe += 2;
}
grain
else if( !strncasecmp( s, "grain", 5 ) )
{
if( psy_tuning_used++ ) goto psy_failure;
//环路滤波alphac和beta都为-2
param->i_deblocking_filter_alphac0 = -2;
param->i_deblocking_filter_beta = -2;
//trellis量化强度0.25
param->analyse.f_psy_trellis = 0.25;
param->analyse.b_dct_decimate = 0;
//P帧到B帧的qscale转换因子1.1
param->rc.f_pb_factor = 1.1;
//P帧到I帧的qscale转换因子1.1
param->rc.f_ip_factor = 1.1;
//adaptive qp强度0.5
param->rc.f_aq_strength = 0.5;
//intra和inter的亮度死区大小
param->analyse.i_luma_deadzone[0] = 6;
param->analyse.i_luma_deadzone[1] = 6;
//非线性压缩系数0.8
param->rc.f_qcompress = 0.8;
}
stillimage
else if( !strncasecmp( s, "stillimage", 10 ) )
{
if( psy_tuning_used++ ) goto psy_failure;
//环路滤波alphac和beta都为-3
param->i_deblocking_filter_alphac0 = -3;
param->i_deblocking_filter_beta = -3;
//psy rd强度2.0
param->analyse.f_psy_rd = 2.0;
//trellis量化强度0.7
param->analyse.f_psy_trellis = 0.7;
//adaptive qp强度1.2
param->rc.f_aq_strength = 1.2;
}
psnr
else if( !strncasecmp( s, "psnr", 4 ) )
{
if( psy_tuning_used++ ) goto psy_failure;
param->rc.i_aq_mode = X264_AQ_NONE; //不使用adaptive qp
param->analyse.b_psy = 0; //不使用所有psy功能
}
ssim
else if( !strncasecmp( s, "ssim", 4 ) )
{
if( psy_tuning_used++ ) goto psy_failure;
param->rc.i_aq_mode = X264_AQ_AUTOVARIANCE;//使用adaptive qp的模式autovariance
param->analyse.b_psy = 0; //不使用所有psy功能
}
fastdecode
else if( !strncasecmp( s, "fastdecode", 10 ) )
{
param->b_deblocking_filter = 0; //关闭环路滤波
param->b_cabac = 0; //使用cavlc
param->analyse.b_weighted_bipred = 0; //关闭双向权重预测
param->analyse.i_weighted_pred = X264_WEIGHTP_NONE; //关闭P帧权重预测
}
zerolatency
else if( !strncasecmp( s, "zerolatency", 11 ) )
{
param->rc.i_lookahead = 0; //lookahead队列0帧
param->i_sync_lookahead = 0;//线程lookahead队列0帧
param->i_bframe = 0; //不使用B帧
param->b_sliced_threads = 1;//开启slice并行
param->b_vfr_input = 0; //不使用vfr
param->rc.b_mb_tree = 0; //关闭宏块树
}
touhou
else if( !strncasecmp( s, "touhou", 6 ) )
{
if( psy_tuning_used++ ) goto psy_failure;
//同animation,若参考帧列表帧数>1则double,否则1
param->i_frame_reference = param->i_frame_reference > 1 ? param->i_frame_reference*2 : 1;
//环路滤波alphac和beta都为-1
param->i_deblocking_filter_alphac0 = -1;
param->i_deblocking_filter_beta = -1;
//trellis量化强度0.2
param->analyse.f_psy_trellis = 0.2;
//adaptive qp强度1.3
param->rc.f_aq_strength = 1.3;
//若允许inter 16x8 8x16 8x8,则继续允许inter 8x4 4x8 4x4
if( param->analyse.inter & X264_ANALYSE_PSUB16x16 )
param->analyse.inter |= X264_ANALYSE_PSUB8x8;
}