h->param.analyse.intra &= ~X264_ANALYSE_I8x8;
}
h->param.analyse.i_trellis = x264_clip3( h->param.analyse.i_trellis, 0, 2 );
- h->param.rc.i_aq_mode = x264_clip3( h->param.rc.i_aq_mode, 0, 2 );
+ h->param.rc.i_aq_mode = x264_clip3( h->param.rc.i_aq_mode, 0, 3 );
h->param.rc.f_aq_strength = x264_clip3f( h->param.rc.f_aq_strength, 0, 3 );
if( h->param.rc.f_aq_strength == 0 )
h->param.rc.i_aq_mode = 0;
void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame, float *quant_offsets )
{
- /* constants chosen to result in approximately the same overall bitrate as without AQ.
- * FIXME: while they're written in 5 significant digits, they're only tuned to 2. */
- float strength;
- float avg_adj = 0.f;
/* Initialize frame stats */
for( int i = 0; i < 3; i++ )
{
/* Actual adaptive quantization */
else
{
- if( h->param.rc.i_aq_mode == X264_AQ_AUTOVARIANCE )
+ /* constants chosen to result in approximately the same overall bitrate as without AQ.
+ * FIXME: while they're written in 5 significant digits, they're only tuned to 2. */
+ float strength;
+ float avg_adj = 0.f;
+ float bias_strength = 0.f;
+
+ if( h->param.rc.i_aq_mode == X264_AQ_AUTOVARIANCE || h->param.rc.i_aq_mode == X264_AQ_AUTOVARIANCE_BIASED )
{
- float bit_depth_correction = powf(1 << (BIT_DEPTH-8), 0.5f);
+ float bit_depth_correction = 1.f / (1 << (2*(BIT_DEPTH-8)));
float avg_adj_pow2 = 0.f;
for( int mb_y = 0; mb_y < h->mb.i_mb_height; mb_y++ )
for( int mb_x = 0; mb_x < h->mb.i_mb_width; mb_x++ )
{
uint32_t energy = x264_ac_energy_mb( h, mb_x, mb_y, frame );
- float qp_adj = powf( energy + 1, 0.125f );
+ float qp_adj = powf( energy * bit_depth_correction + 1, 0.125f );
frame->f_qp_offset[mb_x + mb_y*h->mb.i_mb_stride] = qp_adj;
avg_adj += qp_adj;
avg_adj_pow2 += qp_adj * qp_adj;
}
avg_adj /= h->mb.i_mb_count;
avg_adj_pow2 /= h->mb.i_mb_count;
- strength = h->param.rc.f_aq_strength * avg_adj / bit_depth_correction;
- avg_adj = avg_adj - 0.5f * (avg_adj_pow2 - (14.f * bit_depth_correction)) / avg_adj;
+ strength = h->param.rc.f_aq_strength * avg_adj;
+ avg_adj = avg_adj - 0.5f * (avg_adj_pow2 - 14.f) / avg_adj;
+ bias_strength = h->param.rc.f_aq_strength;
}
else
strength = h->param.rc.f_aq_strength * 1.0397f;
{
float qp_adj;
int mb_xy = mb_x + mb_y*h->mb.i_mb_stride;
- if( h->param.rc.i_aq_mode == X264_AQ_AUTOVARIANCE )
+ if( h->param.rc.i_aq_mode == X264_AQ_AUTOVARIANCE_BIASED )
+ {
+ qp_adj = frame->f_qp_offset[mb_xy];
+ qp_adj = strength * (qp_adj - avg_adj) + bias_strength * (1.f - 14.f / (qp_adj * qp_adj));
+ }
+ else if( h->param.rc.i_aq_mode == X264_AQ_AUTOVARIANCE )
{
qp_adj = frame->f_qp_offset[mb_xy];
qp_adj = strength * (qp_adj - avg_adj);
H2( " --aq-mode <integer> AQ method [%d]\n"
" - 0: Disabled\n"
" - 1: Variance AQ (complexity mask)\n"
- " - 2: Auto-variance AQ (experimental)\n", defaults->rc.i_aq_mode );
+ " - 2: Auto-variance AQ\n"
+ " - 3: Auto-variance AQ with bias to dark scenes\n", defaults->rc.i_aq_mode );
H1( " --aq-strength <float> Reduces blocking and blurring in flat and\n"
" textured areas. [%.1f]\n", defaults->rc.f_aq_strength );
H1( "\n" );
#include "x264_config.h"
-#define X264_BUILD 143
+#define X264_BUILD 144
/* Application developers planning to link against a shared library version of
* libx264 from a Microsoft Visual Studio or similar development environment
#define X264_AQ_NONE 0
#define X264_AQ_VARIANCE 1
#define X264_AQ_AUTOVARIANCE 2
+#define X264_AQ_AUTOVARIANCE_BIASED 3
#define X264_B_ADAPT_NONE 0
#define X264_B_ADAPT_FAST 1
#define X264_B_ADAPT_TRELLIS 2