From 2fae99911e7deff3759a9fbd9d00f4975fceb1d9 Mon Sep 17 00:00:00 2001 From: Marco Paniconi Date: Thu, 2 Aug 2018 09:22:58 -0700 Subject: [PATCH] vp9: Disable re_encode_overshoot feature for speed >= 6. For real-time screen content mode: for speed >= 6 disable the re_encode_overshoot feature. This means for speed >= 6 the Q and rate control is reset on slide changes based on the scene/slide detection and the current Q (and not on a first pass encoded frame at current Q). This reduces encode time on slide changes, but may be less accurate in deciding when to reset/max-out the Q. Change-Id: Id0fdcafd55bc43bd8b3afee211e524f37c8ddce6 --- vp9/encoder/vp9_encoder.c | 12 ++++++++++++ vp9/encoder/vp9_ratectrl.c | 12 ++++++++++-- vp9/encoder/vp9_speed_features.c | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index 868a6249a..fa4571cea 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -4052,6 +4052,18 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, vp9_svc_assert_constraints_pattern(cpi); } + if (!cpi->sf.re_encode_overshoot_rt && + (cpi->rc.high_source_sad || + (cpi->use_svc && cpi->svc.high_source_sad_superframe))) { + // Check if this high_source_sad (scene/slide change) frame should be + // encoded at high/max QP, and if so, set the q and adjust some rate + // control parameters. + if (vp9_encodedframe_overshoot(cpi, -1, &q)) { + vp9_set_quantizer(cm, q); + vp9_set_variance_partition_thresholds(cpi, q, 0); + } + } + // Variance adaptive and in frame q adjustment experiments are mutually // exclusive. if (cpi->oxcf.aq_mode == VARIANCE_AQ) { diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index ec969e0cc..695b15526 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -2803,15 +2803,22 @@ void vp9_scene_detection_onepass(VP9_COMP *cpi) { // Test if encoded frame will significantly overshoot the target bitrate, and // if so, set the QP, reset/adjust some rate control parameters, and return 1. +// frame_size = -1 means frame has not been encoded. int vp9_encodedframe_overshoot(VP9_COMP *cpi, int frame_size, int *q) { VP9_COMMON *const cm = &cpi->common; RATE_CONTROL *const rc = &cpi->rc; + SPEED_FEATURES *const sf = &cpi->sf; int thresh_qp = 7 * (rc->worst_quality >> 3); int thresh_rate = rc->avg_frame_bandwidth << 3; // Lower rate threshold for video. if (cpi->oxcf.content != VP9E_CONTENT_SCREEN) thresh_rate = rc->avg_frame_bandwidth << 2; - if (cm->base_qindex < thresh_qp && frame_size > thresh_rate) { + // If this decision is not based on an encoded frame size but just on + // scene/slide change detection (i.e., re_encode_overshoot_rt = 0), adjust the + // qp_thresh and skip the (frame_size > thresh_rate) condition in this case. + if (!sf->re_encode_overshoot_rt) thresh_qp = rc->worst_quality >> 1; + if ((!sf->re_encode_overshoot_rt || frame_size > thresh_rate) && + cm->base_qindex < thresh_qp) { double rate_correction_factor = cpi->rc.rate_correction_factors[INTER_NORMAL]; const int target_size = cpi->rc.avg_frame_bandwidth; @@ -2827,7 +2834,8 @@ int vp9_encodedframe_overshoot(VP9_COMP *cpi, int frame_size, int *q) { // and the encoded frame used alot of Intra modes, then force hybrid_intra // encoding for the re-encode on this scene change. hybrid_intra will // use rd-based intra mode selection for small blocks. - if (frame_size > (thresh_rate << 1) && cpi->svc.spatial_layer_id == 0) { + if (sf->re_encode_overshoot_rt && frame_size > (thresh_rate << 1) && + cpi->svc.spatial_layer_id == 0) { MODE_INFO **mi = cm->mi_grid_visible; int sum_intra_usage = 0; int mi_row, mi_col; diff --git a/vp9/encoder/vp9_speed_features.c b/vp9/encoder/vp9_speed_features.c index fb3d231e9..347139011 100644 --- a/vp9/encoder/vp9_speed_features.c +++ b/vp9/encoder/vp9_speed_features.c @@ -581,6 +581,7 @@ static void set_rt_speed_feature_framesize_independent( } if (speed >= 6) { + sf->re_encode_overshoot_rt = 0; if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0) { sf->use_altref_onepass = 1; sf->use_compound_nonrd_pickmode = 1; -- 2.40.0