odrling-overlay/media-libs/x264/files/fadecomp.patch
2021-05-02 22:21:02 +02:00

114 lines
5.2 KiB
Diff

From 43e589ef727752f459ee1dec5bc8d274c3c2db42 Mon Sep 17 00:00:00 2001
From: DJATOM <djatom@beatrice-raws.org>
Date: Tue, 26 Jan 2021 01:47:09 +0200
Subject: [PATCH] Add --fade-compensate option
Allocates more bitrate on fades
---
common/base.c | 5 +++++
encoder/encoder.c | 5 +++++
encoder/slicetype.c | 4 ++--
x264.c | 3 +++
x264.h | 1 +
5 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/common/base.c b/common/base.c
index 7a230ade..e1baeeb5 100644
--- a/common/base.c
+++ b/common/base.c
@@ -1322,6 +1322,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("fade-compensate")
+ p->rc.f_fade_compensate = atof(value);
OPT("pass")
{
int pass = x264_clip3( atoi(value), 0, 3 );
@@ -1460,7 +1462,10 @@ char *x264_param2string( x264_param_t *p, int b_res )
s += sprintf( s, " subme=%d", p->analyse.i_subpel_refine );
s += sprintf( s, " psy=%d", p->analyse.b_psy );
if( p->analyse.b_psy )
+ {
+ s += sprintf( s, " fade_compensate=%.2f", p->rc.f_fade_compensate );
s += sprintf( s, " psy_rd=%.2f:%.2f", p->analyse.f_psy_rd, p->analyse.f_psy_trellis );
+ }
s += sprintf( s, " mixed_ref=%d", p->analyse.b_mixed_references );
s += sprintf( s, " me_range=%d", p->analyse.i_me_range );
s += sprintf( s, " chroma_me=%d", p->analyse.b_chroma_me );
diff --git a/encoder/encoder.c b/encoder/encoder.c
index 266e91ec..ca5f39c9 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -1154,10 +1154,15 @@ static int validate_parameters( x264_t *h, int b_open )
x264_log( h, X264_LOG_WARNING, "--tune %s should be used if attempting to benchmark %s!\n", s, s );
}
+ if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_NONE )
+ h->param.rc.f_fade_compensate += 0.1;
+ if( !h->param.rc.b_mb_tree )
+ h->param.rc.f_fade_compensate = 0;
if( !h->param.analyse.b_psy )
{
h->param.analyse.f_psy_rd = 0;
h->param.analyse.f_psy_trellis = 0;
+ h->param.rc.f_fade_compensate = 0;
}
h->param.analyse.f_psy_rd = x264_clip3f( h->param.analyse.f_psy_rd, 0, 10 );
h->param.analyse.f_psy_trellis = x264_clip3f( h->param.analyse.f_psy_trellis, 0, 10 );
diff --git a/encoder/slicetype.c b/encoder/slicetype.c
index b2e0e335..0972cc75 100644
--- a/encoder/slicetype.c
+++ b/encoder/slicetype.c
@@ -460,7 +460,7 @@ void x264_weights_analyse( x264_t *h, x264_frame_t *fenc, x264_frame_t *ref, int
else
SET_WEIGHT( weights[plane], 1, minscale, mindenom, minoff );
- if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_FAKE && weights[0].weightfn && !plane )
+ if( weights[0].weightfn && !plane )
fenc->f_weighted_cost_delta[i_delta_index] = (float)minscore / origscore;
}
@@ -1032,7 +1032,7 @@ static void macroblock_tree_finish( x264_t *h, x264_frame_t *frame, float averag
int fps_factor = round( CLIP_DURATION(average_duration) / CLIP_DURATION(frame->f_duration) * 256 / MBTREE_PRECISION );
float weightdelta = 0.0;
if( ref0_distance && frame->f_weighted_cost_delta[ref0_distance-1] > 0 )
- weightdelta = (1.0 - frame->f_weighted_cost_delta[ref0_distance-1]);
+ weightdelta = (1.0 - frame->f_weighted_cost_delta[ref0_distance-1]) * 10.0f * h->param.rc.f_fade_compensate;
/* Allow the strength to be adjusted via qcompress, since the two
* concepts are very similar. */
diff --git a/x264.c b/x264.c
index a12fa099..9dbd9831 100644
--- a/x264.c
+++ b/x264.c
@@ -812,6 +812,8 @@ 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( " --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" );
H0( " -p, --pass <integer> Enable multipass ratecontrol\n"
" - 1: First pass, creates stats file\n"
@@ -1160,6 +1162,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 },
+ { "fade-compensate", required_argument, NULL, 0 },
{ "deadzone-inter", required_argument, NULL, 0 },
{ "deadzone-intra", required_argument, NULL, 0 },
{ "level", required_argument, NULL, 0 },
diff --git a/x264.h b/x264.h
index 8689aa03..18abda8e 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_fade_compensate; /* Give more bits to fades. */
int b_mb_tree; /* Macroblock-tree ratecontrol. */
int i_lookahead;