From: Anton Mitrofanov Date: Sat, 23 Apr 2016 20:10:03 +0000 (+0300) Subject: Apply zone options a little bit earlier X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=740a8c556bd9b68e899d6991f3f987a443aa14aa;p=libx264 Apply zone options a little bit earlier This way things like SAR changes will have full effect from the start frame. --- diff --git a/encoder/encoder.c b/encoder/encoder.c index b614198a..f733adf2 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -3344,6 +3344,7 @@ int x264_encoder_encode( x264_t *h, h->fenc->param = NULL; } } + x264_ratecontrol_zone_init( h ); // ok to call this before encoding any frames, since the initial values of fdec have b_kept_as_ref=0 if( x264_reference_update( h ) ) diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 723350c5..99277f1d 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -1409,6 +1409,15 @@ static void accum_p_qp_update( x264_t *h, float qp ) rc->accum_p_qp += qp; } +void x264_ratecontrol_zone_init( x264_t *h ) +{ + x264_ratecontrol_t *rc = h->rc; + x264_zone_t *zone = get_zone( h, h->fenc->i_frame ); + if( zone && (!rc->prev_zone || zone->param != rc->prev_zone->param) ) + x264_encoder_reconfig_apply( h, zone->param ); + rc->prev_zone = zone; +} + /* Before encoding a frame, choose a QP for it */ void x264_ratecontrol_start( x264_t *h, int i_force_qp, int overhead ) { @@ -1419,10 +1428,6 @@ void x264_ratecontrol_start( x264_t *h, int i_force_qp, int overhead ) x264_emms(); - if( zone && (!rc->prev_zone || zone->param != rc->prev_zone->param) ) - x264_encoder_reconfig_apply( h, zone->param ); - rc->prev_zone = zone; - if( h->param.rc.b_stat_read ) { int frame = h->fenc->i_frame; diff --git a/encoder/ratecontrol.h b/encoder/ratecontrol.h index 490a1edb..9f7e227c 100644 --- a/encoder/ratecontrol.h +++ b/encoder/ratecontrol.h @@ -49,6 +49,7 @@ void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame, float *quant_off int x264_macroblock_tree_read( x264_t *h, x264_frame_t *frame, float *quant_offsets ); int x264_reference_build_list_optimal( x264_t *h ); void x264_thread_sync_ratecontrol( x264_t *cur, x264_t *prev, x264_t *next ); +void x264_ratecontrol_zone_init( x264_t * ); void x264_ratecontrol_start( x264_t *, int i_force_qp, int overhead ); int x264_ratecontrol_slice_type( x264_t *, int i_frame ); void x264_ratecontrol_set_weights( x264_t *h, x264_frame_t *frm );