[x264-devel] Fix high bit depth lookahead cost compensation algorithm
Anton Mitrofanov
git at videolan.org
Sun Oct 11 19:01:08 CEST 2015
x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Tue Sep 22 19:26:25 2015 +0300| [001d30598c75d9bbc3aa80f67f9bdac17692437d] | committer: Henrik Gramner
Fix high bit depth lookahead cost compensation algorithm
Now high bit depth VBV should act more like 8-bit depth one.
> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=001d30598c75d9bbc3aa80f67f9bdac17692437d
---
encoder/ratecontrol.c | 8 ++++----
encoder/slicetype.c | 10 +++-------
2 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
index c692691..8b8e76e 100644
--- a/encoder/ratecontrol.c
+++ b/encoder/ratecontrol.c
@@ -201,11 +201,11 @@ static void update_predictor( predictor_t *p, float q, float var, float bits );
*/
static inline float qp2qscale( float qp )
{
- return 0.85f * powf( 2.0f, ( qp - 12.0f ) / 6.0f );
+ return 0.85f * powf( 2.0f, ( qp - (12.0f + QP_BD_OFFSET) ) / 6.0f );
}
static inline float qscale2qp( float qscale )
{
- return 12.0f + 6.0f * log2f( qscale/0.85f );
+ return (12.0f + QP_BD_OFFSET) + 6.0f * log2f( qscale/0.85f );
}
/* Texture bitrate is not quite inversely proportional to qscale,
@@ -828,7 +828,7 @@ int x264_ratecontrol_new( x264_t *h )
h->mb.ip_offset = rc->ip_offset + 0.5;
rc->lstep = pow( 2, h->param.rc.i_qp_step / 6.0 );
- rc->last_qscale = qp2qscale( 26 );
+ rc->last_qscale = qp2qscale( 26 + QP_BD_OFFSET );
int num_preds = h->param.b_sliced_threads * h->param.i_threads + 1;
CHECKED_MALLOC( rc->pred, 5 * sizeof(predictor_t) * num_preds );
CHECKED_MALLOC( rc->pred_b_from_p, sizeof(predictor_t) );
@@ -1024,7 +1024,7 @@ int x264_ratecontrol_new( x264_t *h )
{
ratecontrol_entry_t *rce = &rc->entry[i];
rce->pict_type = SLICE_TYPE_P;
- rce->qscale = rce->new_qscale = qp2qscale( 20 );
+ rce->qscale = rce->new_qscale = qp2qscale( 20 + QP_BD_OFFSET );
rce->misc_bits = rc->nmb + 10;
rce->new_qp = 0;
}
diff --git a/encoder/slicetype.c b/encoder/slicetype.c
index 9900765..51e94bf 100644
--- a/encoder/slicetype.c
+++ b/encoder/slicetype.c
@@ -740,7 +740,7 @@ lowres_intra_mb:
}
}
- i_icost += intra_penalty + lowres_penalty;
+ i_icost = ((i_icost + intra_penalty) >> (BIT_DEPTH - 8)) + lowres_penalty;
fenc->i_intra_cost[i_mb_xy] = i_icost;
int i_icost_aq = i_icost;
if( h->param.rc.i_aq_mode )
@@ -752,7 +752,7 @@ lowres_intra_mb:
output_intra[COST_EST_AQ] += i_icost_aq;
}
}
- i_bcost += lowres_penalty;
+ i_bcost = (i_bcost >> (BIT_DEPTH - 8)) + lowres_penalty;
/* forbid intra-mbs in B-frames, because it's rare and not worth checking */
/* FIXME: Should we still forbid them now that we cache intra scores? */
@@ -2069,9 +2069,5 @@ int x264_rc_analyse_slice( x264_t *h )
}
}
- if( BIT_DEPTH > 8 )
- for( int y = 0; y < h->mb.i_mb_height; y++ )
- h->fdec->i_row_satd[y] >>= (BIT_DEPTH - 8);
-
- return cost >> (BIT_DEPTH - 8);
+ return cost;
}
More information about the x264-devel
mailing list