diff options
Diffstat (limited to 'vp9/encoder/vp9_firstpass.c')
-rw-r--r-- | vp9/encoder/vp9_firstpass.c | 94 |
1 files changed, 42 insertions, 52 deletions
diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 430f71394..5e82bb3f4 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -594,31 +594,28 @@ void vp9_first_pass(VP9_COMP *cpi) { // Other than for the first frame do a motion search. if (cm->current_video_frame > 0) { - int tmp_err, motion_error; + int tmp_err, motion_error, raw_motion_error; int_mv mv, tmp_mv; - int raw_motion_error; struct buf_2d unscaled_last_source_buf_2d; xd->plane[0].pre[0].buf = first_ref_buf->y_buffer + recon_yoffset; motion_error = get_prediction_error(bsize, &x->plane[0].src, &xd->plane[0].pre[0]); - - // compute the motion error of the zero motion vector using the last - // source frame as the reference - // skip the further motion search on reconstructed frame - // if this error is small - unscaled_last_source_buf_2d.buf = cpi->unscaled_last_source->y_buffer - + recon_yoffset; + // Assume 0,0 motion with no mv overhead. + mv.as_int = tmp_mv.as_int = 0; + + // Compute the motion error of the 0,0 motion using the last source + // frame as the reference. Skip the further motion search on + // reconstructed frame if this error is small. + unscaled_last_source_buf_2d.buf = + cpi->unscaled_last_source->y_buffer + recon_yoffset; unscaled_last_source_buf_2d.stride = - cpi->unscaled_last_source->y_stride; + cpi->unscaled_last_source->y_stride; raw_motion_error = get_prediction_error(bsize, &x->plane[0].src, &unscaled_last_source_buf_2d); // TODO(pengchong): Replace the hard-coded threshold if (raw_motion_error > 25) { - // Assume 0,0 motion with no mv overhead. - mv.as_int = tmp_mv.as_int = 0; - // Test last reference frame using the previous best mv as the // starting point (best reference) for the search. first_pass_motion_search(cpi, x, &best_ref_mv.as_mv, &mv.as_mv, @@ -628,13 +625,11 @@ void vp9_first_pass(VP9_COMP *cpi) { motion_error = (int)(motion_error * error_weight); } - // If the current best reference mv is not centered on 0,0 - // then do a 0,0 - // based search as well. + // If the current best reference mv is not centered on 0,0 then do a + // 0,0 based search as well. if (best_ref_mv.as_int) { tmp_err = INT_MAX; - first_pass_motion_search(cpi, x, &zero_mv, &tmp_mv.as_mv, - &tmp_err); + first_pass_motion_search(cpi, x, &zero_mv, &tmp_mv.as_mv, &tmp_err); if (cpi->oxcf.aq_mode == VARIANCE_AQ) { vp9_clear_system_state(); tmp_err = (int)(tmp_err * error_weight); @@ -681,7 +676,10 @@ void vp9_first_pass(VP9_COMP *cpi) { } else { sr_coded_error += motion_error; } + } else { + sr_coded_error += motion_error; } + // Start by assuming that intra mode is best. best_ref_mv.as_int = 0; @@ -922,7 +920,7 @@ static int get_twopass_worst_quality(const VP9_COMP *cpi, } // Restriction on active max q for constrained quality mode. - if (cpi->oxcf.rc_mode == RC_MODE_CONSTRAINED_QUALITY) + if (cpi->oxcf.rc_mode == VPX_CQ) q = MAX(q, oxcf->cq_level); return q; } @@ -1083,38 +1081,30 @@ static int detect_flash(const TWO_PASS *twopass, int offset) { } // Update the motion related elements to the GF arf boost calculation. -static void accumulate_frame_motion_stats( - FIRSTPASS_STATS *this_frame, - double *this_frame_mv_in_out, - double *mv_in_out_accumulator, - double *abs_mv_in_out_accumulator, - double *mv_ratio_accumulator) { - double motion_pct; - - // Accumulate motion stats. - motion_pct = this_frame->pcnt_motion; +static void accumulate_frame_motion_stats(const FIRSTPASS_STATS *stats, + double *mv_in_out, + double *mv_in_out_accumulator, + double *abs_mv_in_out_accumulator, + double *mv_ratio_accumulator) { + const double pct = stats->pcnt_motion; // Accumulate Motion In/Out of frame stats. - *this_frame_mv_in_out = this_frame->mv_in_out_count * motion_pct; - *mv_in_out_accumulator += this_frame->mv_in_out_count * motion_pct; - *abs_mv_in_out_accumulator += fabs(this_frame->mv_in_out_count * motion_pct); - - // Accumulate a measure of how uniform (or conversely how random) - // the motion field is (a ratio of absmv / mv). - if (motion_pct > 0.05) { - const double this_frame_mvr_ratio = fabs(this_frame->mvr_abs) / - DOUBLE_DIVIDE_CHECK(fabs(this_frame->MVr)); - - const double this_frame_mvc_ratio = fabs(this_frame->mvc_abs) / - DOUBLE_DIVIDE_CHECK(fabs(this_frame->MVc)); - - *mv_ratio_accumulator += (this_frame_mvr_ratio < this_frame->mvr_abs) - ? (this_frame_mvr_ratio * motion_pct) - : this_frame->mvr_abs * motion_pct; - - *mv_ratio_accumulator += (this_frame_mvc_ratio < this_frame->mvc_abs) - ? (this_frame_mvc_ratio * motion_pct) - : this_frame->mvc_abs * motion_pct; + *mv_in_out = stats->mv_in_out_count * pct; + *mv_in_out_accumulator += *mv_in_out; + *abs_mv_in_out_accumulator += fabs(*mv_in_out); + + // Accumulate a measure of how uniform (or conversely how random) the motion + // field is (a ratio of abs(mv) / mv). + if (pct > 0.05) { + const double mvr_ratio = fabs(stats->mvr_abs) / + DOUBLE_DIVIDE_CHECK(fabs(stats->MVr)); + const double mvc_ratio = fabs(stats->mvc_abs) / + DOUBLE_DIVIDE_CHECK(fabs(stats->MVc)); + + *mv_ratio_accumulator += pct * (mvr_ratio < stats->mvr_abs ? + mvr_ratio : stats->mvr_abs); + *mv_ratio_accumulator += pct * (mvc_ratio < stats->mvc_abs ? + mvc_ratio : stats->mvc_abs); } } @@ -2152,7 +2142,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { rc->base_frame_target = target_rate; #ifdef LONG_TERM_VBR_CORRECTION // Correction to rate target based on prior over or under shoot. - if (cpi->oxcf.rc_mode == RC_MODE_VBR) + if (cpi->oxcf.rc_mode == VPX_VBR) vbr_rate_correction(&target_rate, rc->vbr_bits_off_target); #endif vp9_rc_set_frame_target(cpi, target_rate); @@ -2167,7 +2157,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { twopass->gf_intra_err_min = GF_MB_INTRA_MIN * cpi->common.MBs; } - if (cpi->oxcf.rc_mode == RC_MODE_CONSTANT_QUALITY) { + if (cpi->oxcf.rc_mode == VPX_Q) { twopass->active_worst_quality = cpi->oxcf.cq_level; } else if (cm->current_video_frame == 0 || (is_spatial_svc && lc->current_video_frame_in_layer == 0)) { @@ -2252,7 +2242,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { rc->base_frame_target = target_rate; #ifdef LONG_TERM_VBR_CORRECTION // Correction to rate target based on prior over or under shoot. - if (cpi->oxcf.rc_mode == RC_MODE_VBR) + if (cpi->oxcf.rc_mode == VPX_VBR) vbr_rate_correction(&target_rate, rc->vbr_bits_off_target); #endif vp9_rc_set_frame_target(cpi, target_rate); |