Skip to content

Instantly share code, notes, and snippets.

@noizuy
Last active October 21, 2022 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noizuy/588446e288164fd4792c9406bc0b1416 to your computer and use it in GitHub Desktop.
Save noizuy/588446e288164fd4792c9406bc0b1416 to your computer and use it in GitHub Desktop.
x264-aMod patch to add the aq-bias-strength parameter. For x264-aMod. Should be easily ported to tmod.
diff --git a/common/base.c b/common/base.c
index c249b141..6e2f3bf4 100644
--- a/common/base.c
+++ b/common/base.c
@@ -416,6 +416,7 @@ REALIGN_STACK void x264_param_default( x264_param_t *param )
param->rc.f_pb_factor = 1.3;
param->rc.i_aq_mode = X264_AQ_VARIANCE;
param->rc.f_aq_strength = 1.0;
+ param->rc.f_aq_bias_strength = 1.0;
param->rc.i_lookahead = 40;
param->rc.b_stat_write = 0;
@@ -1360,6 +1361,8 @@ REALIGN_STACK int x264_param_parse( x264_param_t *p, const char *name, const cha
p->rc.i_aq_mode = atoi(value);
OPT("aq-strength")
p->rc.f_aq_strength = atof(value);
+ OPT("aq-bias-strength")
+ p->rc.f_aq_bias_strength = atof(value);
OPT("fade-compensate")
p->rc.f_fade_compensate = atof(value);
OPT("pass")
@@ -1605,7 +1608,11 @@ char *x264_param2string( x264_param_t *p, int b_res )
s += sprintf( s, " pb_ratio=%.2f", p->rc.f_pb_factor );
s += sprintf( s, " aq=%d", p->rc.i_aq_mode );
if( p->rc.i_aq_mode )
+ {
s += sprintf( s, ":%.2f", p->rc.f_aq_strength );
+ if( p->rc.i_aq_mode == X264_AQ_AUTOVARIANCE_BIASED )
+ s += sprintf( s, ":%.2f", p->rc.f_aq_bias_strength );
+ }
if( p->rc.psz_zones )
s += sprintf( s, " zones=%s", p->rc.psz_zones );
else if( p->rc.i_zones )
diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
index 0021be3b..1783e8fc 100644
--- a/encoder/ratecontrol.c
+++ b/encoder/ratecontrol.c
@@ -368,7 +368,7 @@ void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame, float *quant_off
avg_adj_pow2 /= h->mb.i_mb_count;
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;
+ bias_strength = h->param.rc.f_aq_strength * h->param.rc.f_aq_bias_strength;
}
else
strength = h->param.rc.f_aq_strength * 1.0397f;
diff --git a/x264.c b/x264.c
index 5ca178a6..646f61b8 100644
--- a/x264.c
+++ b/x264.c
@@ -824,6 +824,7 @@ static void help( x264_param_t *defaults, int longhelp )
" - 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( " --aq-bias-strength <float> Adjust the bias to darks strength in AQ mode 3 [%.1f]\n", defaults->rc.f_aq_bias_strength );
H1( " --fade-compensate <float> Allocate more bits to fades [%.1f]\n", defaults->rc.f_fade_compensate );
H2( " Approximate sane range: 0.0 - 1.0\n" );
H1( "\n" );
@@ -1182,6 +1183,7 @@ static struct option long_options[] =
{ "no-dct-decimate", no_argument, NULL, 0 },
{ "aq-strength", required_argument, NULL, 0 },
{ "aq-mode", required_argument, NULL, 0 },
+ { "aq-bias-strength", required_argument, NULL, 0 },
{ "fade-compensate", required_argument, NULL, 0 },
{ "deadzone-inter", required_argument, NULL, 0 },
{ "deadzone-intra", required_argument, NULL, 0 },
diff --git a/x264.h b/x264.h
index 82939e81..549501fe 100644
--- a/x264.h
+++ b/x264.h
@@ -469,6 +469,7 @@ typedef struct x264_param_t
int i_aq_mode; /* psy adaptive QP. (X264_AQ_*) */
float f_aq_strength;
+ float f_aq_bias_strength; /* Fine-tune AQ mode 3 dark bias. */
float f_fade_compensate; /* Give more bits to fades. */
int b_mb_tree; /* Macroblock-tree ratecontrol. */
int i_lookahead;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment