From 2adc0443dd3701d0236a44e9e0670b50c15d30a2 Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 21 May 2017 22:15:28 -0700 Subject: [PATCH] vp9: Adjustments to cyclic refresh for high motion. For aq-mode=3: refactor the condition for turning off the refresh. Add some adjustments for high motion content. No/little change in RTC metrics, only affects high motion case. Change-Id: I7da8eabfb0e61db014be4562806f72ee5ef4a43b --- vp9/encoder/vp9_aq_cyclicrefresh.c | 19 ++++++++++--------- vp9/encoder/vp9_aq_cyclicrefresh.h | 1 + vp9/encoder/vp9_ratectrl.c | 3 ++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.c b/vp9/encoder/vp9_aq_cyclicrefresh.c index b4a0bbe58..048ea629f 100644 --- a/vp9/encoder/vp9_aq_cyclicrefresh.c +++ b/vp9/encoder/vp9_aq_cyclicrefresh.c @@ -277,8 +277,6 @@ void vp9_cyclic_refresh_postencode(VP9_COMP *const cpi) { !cpi->oxcf.gf_cbr_boost_pct) { // Force this frame as a golden update frame if this frame changes the // resolution (resize_pending != 0). - // TODO(marpan): check on forcing golden update if the background has very - // high motion in current frame. if (cpi->resize_pending != 0) { vp9_cyclic_refresh_set_golden_update(cpi); rc->frames_till_gf_update_due = rc->baseline_gf_interval; @@ -316,6 +314,8 @@ void vp9_cyclic_refresh_set_golden_update(VP9_COMP *const cpi) { else rc->baseline_gf_interval = 40; if (cpi->oxcf.rc_mode == VPX_VBR) rc->baseline_gf_interval = 20; + if (rc->avg_frame_low_motion < 50 && rc->frames_since_key > 40) + rc->baseline_gf_interval = 10; } // Update the segmentation map, and related quantities: cyclic refresh map, @@ -425,6 +425,13 @@ void vp9_cyclic_refresh_update_parameters(VP9_COMP *const cpi) { int target_refresh = 0; double weight_segment_target = 0; double weight_segment = 0; + cr->apply_cyclic_refresh = 1; + if (cm->frame_type == KEY_FRAME || cpi->svc.temporal_layer_id > 0 || + (!cpi->use_svc && rc->avg_frame_low_motion < 55 && + rc->frames_since_key > 40)) { + cr->apply_cyclic_refresh = 0; + return; + } cr->percent_refresh = 10; if (cr->reduce_refresh) cr->percent_refresh = 5; cr->max_qdelta_perc = 60; @@ -493,14 +500,8 @@ void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) { const RATE_CONTROL *const rc = &cpi->rc; CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; struct segmentation *const seg = &cm->seg; - // TODO(marpan): Look into whether we should reduce the amount/delta-qp - // instead of completely shutting off at low bitrates. For now keep it on. - // const int apply_cyclic_refresh = apply_cyclic_refresh_bitrate(cm, rc); - const int apply_cyclic_refresh = 1; if (cm->current_video_frame == 0) cr->low_content_avg = 0.0; - // Don't apply refresh on key frame or temporal enhancement layer frames. - if (!apply_cyclic_refresh || (cm->frame_type == KEY_FRAME) || - (cpi->force_update_segmentation) || (cpi->svc.temporal_layer_id > 0)) { + if (!cr->apply_cyclic_refresh || (cpi->force_update_segmentation)) { // Set segmentation map to 0 and disable. unsigned char *const seg_map = cpi->segmentation_map; memset(seg_map, 0, cm->mi_rows * cm->mi_cols); diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.h b/vp9/encoder/vp9_aq_cyclicrefresh.h index 9de5074d9..77fa67c9e 100644 --- a/vp9/encoder/vp9_aq_cyclicrefresh.h +++ b/vp9/encoder/vp9_aq_cyclicrefresh.h @@ -67,6 +67,7 @@ struct CYCLIC_REFRESH { int qindex_delta[3]; int reduce_refresh; double weight_segment; + int apply_cyclic_refresh; }; struct VP9_COMP; diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index b1866cd8a..27fea5d4e 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -547,6 +547,7 @@ void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi) { int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame, int active_best_quality, int active_worst_quality) { const VP9_COMMON *const cm = &cpi->common; + CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; int q = active_worst_quality; int last_error = INT_MAX; int i, target_bits_per_mb, bits_per_mb_at_this_q; @@ -561,7 +562,7 @@ int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame, do { if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled && - cpi->svc.temporal_layer_id == 0 && + cr->apply_cyclic_refresh && (!cpi->oxcf.gf_cbr_boost_pct || !cpi->refresh_golden_frame)) { bits_per_mb_at_this_q = (int)vp9_cyclic_refresh_rc_bits_per_mb(cpi, i, correction_factor); -- 2.50.0