From fd527e3760074a19637c503d0f828d97b7c079fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A5ns=20Rullg=C3=A5rd?= Date: Fri, 11 Mar 2005 18:10:35 +0000 Subject: [PATCH] Really fix QP override. git-svn-id: svn://svn.videolan.org/x264/trunk@163 df754926-b1dd-0310-bc7b-ec298dee348c --- encoder/encoder.c | 4 +--- encoder/ratecontrol.c | 19 +++++++++++++++---- encoder/ratecontrol.h | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/encoder/encoder.c b/encoder/encoder.c index a36ab4b7..5793a834 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -1121,10 +1121,8 @@ do_encode: /* ------------------- Init ----------------------------- */ /* Init the rate control */ - x264_ratecontrol_start( h, i_slice_type ); + x264_ratecontrol_start( h, i_slice_type, h->fenc->i_qpplus1 ); i_global_qp = x264_ratecontrol_qp( h ); - if( h->fenc->i_qpplus1 > 0) - i_global_qp = h->fenc->i_qpplus1 - 1; pic_out->i_qpplus1 = h->fdec->i_qpplus1 = i_global_qp + 1; diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 6057515a..3f757ed1 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -100,6 +100,7 @@ struct x264_ratecontrol_t int nzcoeffs; /* # of 0-quantized coefficients */ int ncoeffs; /* total # of coefficients */ int overhead; + int qp_force; /* 2pass stuff */ FILE *p_stat_file_out; @@ -377,7 +378,7 @@ void x264_ratecontrol_delete( x264_t *h ) x264_free( rc ); } -void x264_ratecontrol_start( x264_t *h, int i_slice_type ) +void x264_ratecontrol_start( x264_t *h, int i_slice_type, int i_force_qp ) { x264_ratecontrol_t *rc = h->rc; int gframes, iframes, pframes, bframes; @@ -391,10 +392,14 @@ void x264_ratecontrol_start( x264_t *h, int i_slice_type ) x264_cpu_restore( h->param.cpu ); + rc->qp_force = i_force_qp; + if( !h->param.rc.b_cbr ) { int q; - if( i_slice_type == SLICE_TYPE_B && h->fdec->b_kept_as_ref ) + if( i_force_qp ) + q = i_force_qp - 1; + else if( i_slice_type == SLICE_TYPE_B && h->fdec->b_kept_as_ref ) q = ( rc->qp_constant[ SLICE_TYPE_B ] + rc->qp_constant[ SLICE_TYPE_P ] ) / 2; else q = rc->qp_constant[ i_slice_type ]; @@ -506,8 +511,12 @@ void x264_ratecontrol_start( x264_t *h, int i_slice_type ) else if(rc->fbits < 1.2 * minbits) rc->qp -= 1; - rc->qp = x264_clip3(rc->qp, h->param.rc.i_qp_min, h->param.rc.i_qp_max); - rc->qpm = rc->qp; + if( i_force_qp > 0 ) { + rc->qpm = rc->qpa = rc->qp = i_force_qp - 1; + } else { + rc->qp = rc->qpm = + x264_clip3(rc->qp, h->param.rc.i_qp_min, h->param.rc.i_qp_max); + } x264_log(h, X264_LOG_DEBUG, "fbits=%i, qp=%i, z=%i, min=%i, max=%i\n", rc->fbits, rc->qpm, zn, minbits, maxbits); @@ -543,6 +552,8 @@ void x264_ratecontrol_mb( x264_t *h, int bits ) return; else if(rc->mb == rc->nmb) return; + else if(rc->qp_force > 0) + return; rcoeffs = (rc->nmb - rc->mb) * 16 * 24; rbits = rc->fbits - rc->ufbits; diff --git a/encoder/ratecontrol.h b/encoder/ratecontrol.h index 13475d3b..a7a6a46e 100644 --- a/encoder/ratecontrol.h +++ b/encoder/ratecontrol.h @@ -27,7 +27,7 @@ int x264_ratecontrol_new ( x264_t * ); void x264_ratecontrol_delete( x264_t * ); -void x264_ratecontrol_start( x264_t *, int i_slice_type ); +void x264_ratecontrol_start( x264_t *, int i_slice_type, int i_force_qp ); int x264_ratecontrol_slice_type( x264_t *, int i_frame ); void x264_ratecontrol_mb( x264_t *, int bits ); int x264_ratecontrol_qp( x264_t * ); -- 2.47.3