diff options
-rw-r--r-- | CONTRIBUTING.md | 7 | ||||
-rw-r--r-- | vp8/vp8_cx_iface.c | 38 | ||||
-rw-r--r-- | vp9/encoder/vp9_firstpass.c | 126 | ||||
-rw-r--r-- | vp9/encoder/vp9_firstpass.h | 6 | ||||
-rw-r--r-- | vp9/vp9_cx_iface.c | 151 | ||||
-rw-r--r-- | vpx/vpx_encoder.h | 33 | ||||
-rw-r--r-- | vpxenc.c | 94 |
7 files changed, 287 insertions, 168 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 577c96a6b..7a73a3031 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,10 +19,9 @@ again. All submissions, including submissions by project members, require review. We use a [Gerrit](https://www.gerritcodereview.com) instance hosted at -https://chromium-review.googlesource.com for this purpose. - -See https://www.webmproject.org/code/contribute/submitting-patches for an -example of a typical gerrit workflow. +https://chromium-review.googlesource.com for this purpose. See the +[WebM Project page](https://www.webmproject.org/code/contribute/submitting-patches/) +for additional details. ## Community Guidelines diff --git a/vp8/vp8_cx_iface.c b/vp8/vp8_cx_iface.c index 06ee5d7df..8d3044f6a 100644 --- a/vp8/vp8_cx_iface.c +++ b/vp8/vp8_cx_iface.c @@ -260,15 +260,15 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, // The range below shall be further tuned. RANGE_CHECK(cfg, use_vizier_rc_params, 0, 1); RANGE_CHECK(cfg, active_wq_factor.den, 1, 1000); - RANGE_CHECK(cfg, base_err_per_mb.den, 1, 1000); + RANGE_CHECK(cfg, err_per_mb_factor.den, 1, 1000); RANGE_CHECK(cfg, sr_default_decay_limit.den, 1, 1000); RANGE_CHECK(cfg, sr_diff_factor.den, 1, 1000); - RANGE_CHECK(cfg, kf_err_per_mb.den, 1, 1000); - RANGE_CHECK(cfg, kf_frame_min_boost.den, 1, 1000); - RANGE_CHECK(cfg, kf_frame_max_boost_subs.den, 1, 1000); - RANGE_CHECK(cfg, kf_max_total_boost.den, 1, 1000); - RANGE_CHECK(cfg, gf_max_total_boost.den, 1, 1000); - RANGE_CHECK(cfg, gf_frame_max_boost.den, 1, 1000); + RANGE_CHECK(cfg, kf_err_per_mb_factor.den, 1, 1000); + RANGE_CHECK(cfg, kf_frame_min_boost_factor.den, 1, 1000); + RANGE_CHECK(cfg, kf_frame_max_boost_subs_factor.den, 1, 1000); + RANGE_CHECK(cfg, kf_max_total_boost_factor.den, 1, 1000); + RANGE_CHECK(cfg, gf_max_total_boost_factor.den, 1, 1000); + RANGE_CHECK(cfg, gf_frame_max_boost_factor.den, 1, 1000); RANGE_CHECK(cfg, zm_factor.den, 1, 1000); RANGE_CHECK(cfg, rd_mult_inter_qp_fac.den, 1, 1000); RANGE_CHECK(cfg, rd_mult_arf_qp_fac.den, 1, 1000); @@ -1307,18 +1307,18 @@ static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] = { { 0 }, /* layer_target_bitrate */ 0, /* temporal_layering_mode */ 0, /* use_vizier_rc_params */ - { 0, 1 }, /* active_wq_factor */ - { 0, 1 }, /* base_err_per_mb */ - { 0, 1 }, /* sr_default_decay_limit */ - { 0, 1 }, /* sr_diff_factor */ - { 0, 1 }, /* kf_err_per_mb */ - { 0, 1 }, /* kf_frame_min_boost */ - { 0, 1 }, /* kf_frame_max_boost_first */ - { 0, 1 }, /* kf_frame_max_boost_subs */ - { 0, 1 }, /* kf_max_total_boost */ - { 0, 1 }, /* gf_max_total_boost */ - { 0, 1 }, /* gf_frame_max_boost */ - { 0, 1 }, /* zm_factor */ + { 1, 1 }, /* active_wq_factor */ + { 1, 1 }, /* err_per_mb_factor */ + { 1, 1 }, /* sr_default_decay_limit */ + { 1, 1 }, /* sr_diff_factor */ + { 1, 1 }, /* kf_err_per_mb_factor */ + { 1, 1 }, /* kf_frame_min_boost_factor */ + { 1, 1 }, /* kf_frame_max_boost_first_factor */ + { 1, 1 }, /* kf_frame_max_boost_subs_factor */ + { 1, 1 }, /* kf_max_total_boost_factor */ + { 1, 1 }, /* gf_max_total_boost_factor */ + { 1, 1 }, /* gf_frame_max_boost_factor */ + { 1, 1 }, /* zm_factor */ { 1, 1 }, /* rd_mult_inter_qp_fac */ { 1, 1 }, /* rd_mult_arf_qp_fac */ { 1, 1 }, /* rd_mult_key_qp_fac */ diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 76ef11909..ce7590fe4 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -1832,33 +1832,35 @@ void vp9_init_second_pass(VP9_COMP *cpi) { } /* This function considers how the quality of prediction may be deteriorating - * with distance. It comapres the coded error for the last frame and the + * with distance. It compares the coded error for the last frame and the * second reference frame (usually two frames old) and also applies a factor * based on the extent of INTRA coding. * * The decay factor is then used to reduce the contribution of frames further - * from the alt-ref or golden frame, to the bitframe boost calculation for that + * from the alt-ref or golden frame, to the bitrate boost calculation for that * alt-ref or golden frame. */ static double get_sr_decay_rate(const TWO_PASS *const twopass, const FIRSTPASS_STATS *frame) { double sr_diff = (frame->sr_coded_error - frame->coded_error); double sr_decay = 1.0; - double modified_pct_inter; - double modified_pcnt_intra; - - modified_pct_inter = frame->pcnt_inter; - if ((frame->coded_error > LOW_CODED_ERR_PER_MB) && - ((frame->intra_error / DOUBLE_DIVIDE_CHECK(frame->coded_error)) < - (double)NCOUNT_FRAME_II_THRESH)) { - modified_pct_inter = - frame->pcnt_inter + frame->pcnt_intra_low - frame->pcnt_neutral; - } - modified_pcnt_intra = 100 * (1.0 - modified_pct_inter); + // Do nothing if the second ref to last frame error difference is + // very small or even negative. if ((sr_diff > LOW_SR_DIFF_TRHESH)) { - double sr_diff_part = + const double sr_diff_part = twopass->sr_diff_factor * ((sr_diff * 0.25) / frame->intra_error); + double modified_pct_inter = frame->pcnt_inter; + double modified_pcnt_intra; + + if ((frame->coded_error > LOW_CODED_ERR_PER_MB) && + ((frame->intra_error / DOUBLE_DIVIDE_CHECK(frame->coded_error)) < + (double)NCOUNT_FRAME_II_THRESH)) { + modified_pct_inter = + frame->pcnt_inter + frame->pcnt_intra_low - frame->pcnt_neutral; + } + modified_pcnt_intra = 100 * (1.0 - modified_pct_inter); + sr_decay = 1.0 - sr_diff_part - (INTRA_PART * modified_pcnt_intra); } return VPXMAX(sr_decay, twopass->sr_default_decay_limit); @@ -1878,8 +1880,7 @@ static double get_prediction_decay_rate(const TWO_PASS *const twopass, const FIRSTPASS_STATS *frame_stats) { const double sr_decay_rate = get_sr_decay_rate(twopass, frame_stats); double zero_motion_factor = - twopass->zm_factor * DEFAULT_ZM_FACTOR * - (frame_stats->pcnt_inter - frame_stats->pcnt_motion); + twopass->zm_factor * (frame_stats->pcnt_inter - frame_stats->pcnt_motion); // Clamp value to range 0.0 to 1.0 // This should happen anyway if input values are sensibly clamped but checked @@ -1980,8 +1981,8 @@ static double calc_frame_boost(const FRAME_INFO *frame_info, const double boost_q_correction = VPXMIN((0.5 + (lq * 0.015)), 1.5); const double active_area = calculate_active_area(frame_info, this_frame); - // Underlying boost factor is based on inter error ratio. - frame_boost = (twopass->base_err_per_mb * active_area) / + // Frame booost is based on inter error. + frame_boost = (twopass->err_per_mb * active_area) / DOUBLE_DIVIDE_CHECK(this_frame->coded_error); // Small adjustment for cases where there is a zoom out @@ -2008,7 +2009,7 @@ static double calc_kf_frame_boost(VP9_COMP *cpi, calculate_active_area(&cpi->frame_info, this_frame); double max_boost; - // Underlying boost factor is based on inter error ratio. + // Frame booost is based on inter error. frame_boost = (twopass->kf_err_per_mb * active_area) / DOUBLE_DIVIDE_CHECK(this_frame->coded_error + *sr_accumulator); @@ -2027,7 +2028,7 @@ static double calc_kf_frame_boost(VP9_COMP *cpi, // This value is in line with the minimum per frame boost in the alt_ref // boost calculation. frame_boost = - ((frame_boost + twopass->kf_frame_min_boost) * boost_q_correction); + (frame_boost + twopass->kf_frame_min_boost) * boost_q_correction; // Maximum allowed boost this frame. May be different for first vs subsequent // key frames. @@ -2861,7 +2862,7 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { const int arf_boost = compute_arf_boost(frame_info, twopass, gld_show_idx, f_frames, b_frames, avg_inter_frame_qindex); - rc->gfu_boost = VPXMIN(twopass->gf_max_total_boost, arf_boost); + rc->gfu_boost = VPXMIN((int)twopass->gf_max_total_boost, arf_boost); rc->source_alt_ref_pending = 0; } @@ -3429,12 +3430,12 @@ static void find_next_key_frame(VP9_COMP *cpi, int kf_show_idx) { // Special case for static / slide show content but dont apply // if the kf group is very short. if ((zero_motion_accumulator > 0.99) && (rc->frames_to_key > 8)) { - rc->kf_boost = twopass->kf_max_total_boost; + rc->kf_boost = (int)(twopass->kf_max_total_boost); } else { // Apply various clamps for min and max oost rc->kf_boost = VPXMAX((int)boost_score, (rc->frames_to_key * 3)); rc->kf_boost = VPXMAX(rc->kf_boost, MIN_KF_TOT_BOOST); - rc->kf_boost = VPXMIN(rc->kf_boost, twopass->kf_max_total_boost); + rc->kf_boost = VPXMIN(rc->kf_boost, (int)(twopass->kf_max_total_boost)); } // Work out how many bits to allocate for the key frame itself. @@ -3492,32 +3493,63 @@ static int is_skippable_frame(const VP9_COMP *cpi) { // Configure image size specific vizier parameters. // Later these will be set via additional command line options static void init_vizier_params(TWO_PASS *const twopass, int screen_area) { - // When |use_vizier_rc_params| is 1, we expect the rc parameters have been - // initialized by the pass in values. - // Be careful that parameters below are only initialized to 0, if we do not - // pass values to them. It is desired to take care of each parameter when - // using |use_vizier_rc_params|. - if (twopass->use_vizier_rc_params) return; - - // When |use_vizier_rc_params| is 0, use defaults for now. - twopass->active_wq_factor = AV_WQ_FACTOR; - twopass->base_err_per_mb = BASELINE_ERR_PER_MB; - twopass->sr_default_decay_limit = DEFAULT_DECAY_LIMIT; - twopass->sr_diff_factor = 1.0; - twopass->gf_frame_max_boost = GF_MAX_FRAME_BOOST; - twopass->gf_max_total_boost = MAX_GF_BOOST; - if (screen_area < 1280 * 720) { - twopass->kf_err_per_mb = 2000.0; - } else if (screen_area < 1920 * 1080) { - twopass->kf_err_per_mb = 500.0; + // When |use_vizier_rc_params| is 1, we expect the rc parameters below to + // have been initialised on the command line as adjustment factors such + // that a factor of 1.0 will match the default behavior when + // |use_vizier_rc_params| is 0 + if (twopass->use_vizier_rc_params) { + twopass->active_wq_factor *= AV_WQ_FACTOR; + twopass->err_per_mb *= BASELINE_ERR_PER_MB; + twopass->sr_default_decay_limit *= DEFAULT_DECAY_LIMIT; + if (twopass->sr_default_decay_limit > 1.0) // > 1.0 here makes no sense + twopass->sr_default_decay_limit = 1.0; + twopass->sr_diff_factor *= 1.0; + twopass->gf_frame_max_boost *= GF_MAX_FRAME_BOOST; + twopass->gf_max_total_boost *= MAX_GF_BOOST; + // NOTE: In use max boost has precedence over min boost. So even if min is + // somehow set higher than max the final boost value will be clamped to the + // appropriate maximum. + twopass->kf_frame_min_boost *= KF_MIN_FRAME_BOOST; + twopass->kf_frame_max_boost_first *= KF_MAX_FRAME_BOOST; + twopass->kf_frame_max_boost_subs *= KF_MAX_FRAME_BOOST; + twopass->kf_max_total_boost *= MAX_KF_TOT_BOOST; + twopass->zm_factor *= DEFAULT_ZM_FACTOR; + if (twopass->zm_factor > 1.0) // > 1.0 here makes no sense + twopass->zm_factor = 1.0; + + // Correction for the fact that the kf_err_per_mb_factor default is + // already different for different video formats and ensures that a passed + // in value of 1.0 on the vizier command line will still match the current + // default. + if (screen_area < 1280 * 720) { + twopass->kf_err_per_mb *= 2000.0; + } else if (screen_area < 1920 * 1080) { + twopass->kf_err_per_mb *= 500.0; + } else { + twopass->kf_err_per_mb *= 250.0; + } } else { - twopass->kf_err_per_mb = 250.0; + // When |use_vizier_rc_params| is 0, use defaults. + twopass->active_wq_factor = AV_WQ_FACTOR; + twopass->err_per_mb = BASELINE_ERR_PER_MB; + twopass->sr_default_decay_limit = DEFAULT_DECAY_LIMIT; + twopass->sr_diff_factor = 1.0; + twopass->gf_frame_max_boost = GF_MAX_FRAME_BOOST; + twopass->gf_max_total_boost = MAX_GF_BOOST; + twopass->kf_frame_min_boost = KF_MIN_FRAME_BOOST; + twopass->kf_frame_max_boost_first = KF_MAX_FRAME_BOOST; + twopass->kf_frame_max_boost_subs = KF_MAX_FRAME_BOOST; + twopass->kf_max_total_boost = MAX_KF_TOT_BOOST; + twopass->zm_factor = DEFAULT_ZM_FACTOR; + + if (screen_area < 1280 * 720) { + twopass->kf_err_per_mb = 2000.0; + } else if (screen_area < 1920 * 1080) { + twopass->kf_err_per_mb = 500.0; + } else { + twopass->kf_err_per_mb = 250.0; + } } - twopass->kf_frame_min_boost = KF_MIN_FRAME_BOOST; - twopass->kf_frame_max_boost_first = KF_MAX_FRAME_BOOST; - twopass->kf_frame_max_boost_subs = twopass->kf_frame_max_boost_first; - twopass->kf_max_total_boost = MAX_KF_TOT_BOOST; - twopass->zm_factor = 1.0; } void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { diff --git a/vp9/encoder/vp9_firstpass.h b/vp9/encoder/vp9_firstpass.h index 1418b67a4..cdbcb5241 100644 --- a/vp9/encoder/vp9_firstpass.h +++ b/vp9/encoder/vp9_firstpass.h @@ -228,15 +228,15 @@ typedef struct { // by default values. int use_vizier_rc_params; double active_wq_factor; - double base_err_per_mb; + double err_per_mb; double sr_default_decay_limit; double sr_diff_factor; double kf_err_per_mb; double kf_frame_min_boost; double kf_frame_max_boost_first; // Max for first kf in a chunk. double kf_frame_max_boost_subs; // Max for subsequent mid chunk kfs. - int kf_max_total_boost; - int gf_max_total_boost; + double kf_max_total_boost; + double gf_max_total_boost; double gf_frame_max_boost; double zm_factor; } TWO_PASS; diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index c2ca215f1..438f9b5ed 100644 --- a/vp9/vp9_cx_iface.c +++ b/vp9/vp9_cx_iface.c @@ -352,15 +352,15 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, // The range below shall be further tuned. RANGE_CHECK(cfg, use_vizier_rc_params, 0, 1); RANGE_CHECK(cfg, active_wq_factor.den, 1, 1000); - RANGE_CHECK(cfg, base_err_per_mb.den, 1, 1000); + RANGE_CHECK(cfg, err_per_mb_factor.den, 1, 1000); RANGE_CHECK(cfg, sr_default_decay_limit.den, 1, 1000); RANGE_CHECK(cfg, sr_diff_factor.den, 1, 1000); - RANGE_CHECK(cfg, kf_err_per_mb.den, 1, 1000); - RANGE_CHECK(cfg, kf_frame_min_boost.den, 1, 1000); - RANGE_CHECK(cfg, kf_frame_max_boost_subs.den, 1, 1000); - RANGE_CHECK(cfg, kf_max_total_boost.den, 1, 1000); - RANGE_CHECK(cfg, gf_max_total_boost.den, 1, 1000); - RANGE_CHECK(cfg, gf_frame_max_boost.den, 1, 1000); + RANGE_CHECK(cfg, kf_err_per_mb_factor.den, 1, 1000); + RANGE_CHECK(cfg, kf_frame_min_boost_factor.den, 1, 1000); + RANGE_CHECK(cfg, kf_frame_max_boost_subs_factor.den, 1, 1000); + RANGE_CHECK(cfg, kf_max_total_boost_factor.den, 1, 1000); + RANGE_CHECK(cfg, gf_max_total_boost_factor.den, 1, 1000); + RANGE_CHECK(cfg, gf_frame_max_boost_factor.den, 1, 1000); RANGE_CHECK(cfg, zm_factor.den, 1, 1000); RANGE_CHECK(cfg, rd_mult_inter_qp_fac.den, 1, 1000); RANGE_CHECK(cfg, rd_mult_arf_qp_fac.den, 1, 1000); @@ -662,39 +662,120 @@ static vpx_codec_err_t set_twopass_params_from_config( if (cpi == NULL) return VPX_CODEC_ERROR; cpi->twopass.use_vizier_rc_params = cfg->use_vizier_rc_params; + + // The values set here are factors that will be applied to default values + // to get the final value used in the two pass code. Hence 1.0 will + // match the default behaviour when not using passed in values. + // We also apply limits here to prevent the user from applying settings + // that make no sense. cpi->twopass.active_wq_factor = (double)cfg->active_wq_factor.num / (double)cfg->active_wq_factor.den; - cpi->twopass.base_err_per_mb = - (double)cfg->base_err_per_mb.num / (double)cfg->base_err_per_mb.den; + if (cpi->twopass.active_wq_factor < 0.25) + cpi->twopass.active_wq_factor = 0.25; + else if (cpi->twopass.active_wq_factor > 16.0) + cpi->twopass.active_wq_factor = 16.0; + + cpi->twopass.err_per_mb = + (double)cfg->err_per_mb_factor.num / (double)cfg->err_per_mb_factor.den; + if (cpi->twopass.err_per_mb < 0.25) + cpi->twopass.err_per_mb = 0.25; + else if (cpi->twopass.err_per_mb > 4.0) + cpi->twopass.err_per_mb = 4.0; + cpi->twopass.sr_default_decay_limit = (double)cfg->sr_default_decay_limit.num / (double)cfg->sr_default_decay_limit.den; + if (cpi->twopass.sr_default_decay_limit < 0.25) + cpi->twopass.sr_default_decay_limit = 0.25; + // If the default changes this will need to change. + else if (cpi->twopass.sr_default_decay_limit > 1.33) + cpi->twopass.sr_default_decay_limit = 1.33; + cpi->twopass.sr_diff_factor = (double)cfg->sr_diff_factor.num / (double)cfg->sr_diff_factor.den; - cpi->twopass.kf_err_per_mb = - (double)cfg->kf_err_per_mb.num / (double)cfg->kf_err_per_mb.den; - cpi->twopass.kf_frame_min_boost = - (double)cfg->kf_frame_min_boost.num / (double)cfg->kf_frame_min_boost.den; + if (cpi->twopass.sr_diff_factor < 0.25) + cpi->twopass.sr_diff_factor = 0.25; + else if (cpi->twopass.sr_diff_factor > 4.0) + cpi->twopass.sr_diff_factor = 4.0; + + cpi->twopass.kf_err_per_mb = (double)cfg->kf_err_per_mb_factor.num / + (double)cfg->kf_err_per_mb_factor.den; + if (cpi->twopass.kf_err_per_mb < 0.25) + cpi->twopass.kf_err_per_mb = 0.25; + else if (cpi->twopass.kf_err_per_mb > 4.0) + cpi->twopass.kf_err_per_mb = 4.0; + + cpi->twopass.kf_frame_min_boost = (double)cfg->kf_frame_min_boost_factor.num / + (double)cfg->kf_frame_min_boost_factor.den; + if (cpi->twopass.kf_frame_min_boost < 0.25) + cpi->twopass.kf_frame_min_boost = 0.25; + else if (cpi->twopass.kf_frame_min_boost > 4.0) + cpi->twopass.kf_frame_min_boost = 4.0; + cpi->twopass.kf_frame_max_boost_first = - (double)cfg->kf_frame_max_boost_first.num / - (double)cfg->kf_frame_max_boost_first.den; + (double)cfg->kf_frame_max_boost_first_factor.num / + (double)cfg->kf_frame_max_boost_first_factor.den; + if (cpi->twopass.kf_frame_max_boost_first < 0.25) + cpi->twopass.kf_frame_max_boost_first = 0.25; + else if (cpi->twopass.kf_frame_max_boost_first > 4.0) + cpi->twopass.kf_frame_max_boost_first = 4.0; + cpi->twopass.kf_frame_max_boost_subs = - (double)cfg->kf_frame_max_boost_subs.num / - (double)cfg->kf_frame_max_boost_subs.den; - cpi->twopass.kf_max_total_boost = (int)((double)cfg->kf_max_total_boost.num / - (double)cfg->kf_max_total_boost.den); - cpi->twopass.gf_max_total_boost = (int)((double)cfg->gf_max_total_boost.num / - (double)cfg->gf_max_total_boost.den); - cpi->twopass.gf_frame_max_boost = - (double)cfg->gf_frame_max_boost.num / (double)cfg->gf_frame_max_boost.den; + (double)cfg->kf_frame_max_boost_subs_factor.num / + (double)cfg->kf_frame_max_boost_subs_factor.den; + if (cpi->twopass.kf_frame_max_boost_subs < 0.25) + cpi->twopass.kf_frame_max_boost_subs = 0.25; + else if (cpi->twopass.kf_frame_max_boost_subs > 4.0) + cpi->twopass.kf_frame_max_boost_subs = 4.0; + + cpi->twopass.kf_max_total_boost = (double)cfg->kf_max_total_boost_factor.num / + (double)cfg->kf_max_total_boost_factor.den; + if (cpi->twopass.kf_max_total_boost < 0.25) + cpi->twopass.kf_max_total_boost = 0.25; + else if (cpi->twopass.kf_max_total_boost > 4.0) + cpi->twopass.kf_max_total_boost = 4.0; + + cpi->twopass.gf_max_total_boost = (double)cfg->gf_max_total_boost_factor.num / + (double)cfg->gf_max_total_boost_factor.den; + if (cpi->twopass.gf_max_total_boost < 0.25) + cpi->twopass.gf_max_total_boost = 0.25; + else if (cpi->twopass.gf_max_total_boost > 4.0) + cpi->twopass.gf_max_total_boost = 4.0; + + cpi->twopass.gf_frame_max_boost = (double)cfg->gf_frame_max_boost_factor.num / + (double)cfg->gf_frame_max_boost_factor.den; + if (cpi->twopass.gf_frame_max_boost < 0.25) + cpi->twopass.gf_frame_max_boost = 0.25; + else if (cpi->twopass.gf_frame_max_boost > 4.0) + cpi->twopass.gf_frame_max_boost = 4.0; + cpi->twopass.zm_factor = (double)cfg->zm_factor.num / (double)cfg->zm_factor.den; + if (cpi->twopass.zm_factor < 0.25) + cpi->twopass.zm_factor = 0.25; + else if (cpi->twopass.zm_factor > 2.0) + cpi->twopass.zm_factor = 2.0; + cpi->rd_ctrl.rd_mult_inter_qp_fac = (double)cfg->rd_mult_inter_qp_fac.num / (double)cfg->rd_mult_inter_qp_fac.den; + if (cpi->rd_ctrl.rd_mult_inter_qp_fac < 0.25) + cpi->rd_ctrl.rd_mult_inter_qp_fac = 0.25; + else if (cpi->rd_ctrl.rd_mult_inter_qp_fac > 4.0) + cpi->rd_ctrl.rd_mult_inter_qp_fac = 4.0; + cpi->rd_ctrl.rd_mult_arf_qp_fac = (double)cfg->rd_mult_arf_qp_fac.num / (double)cfg->rd_mult_arf_qp_fac.den; + if (cpi->rd_ctrl.rd_mult_arf_qp_fac < 0.25) + cpi->rd_ctrl.rd_mult_arf_qp_fac = 0.25; + else if (cpi->rd_ctrl.rd_mult_arf_qp_fac > 4.0) + cpi->rd_ctrl.rd_mult_arf_qp_fac = 4.0; + cpi->rd_ctrl.rd_mult_key_qp_fac = (double)cfg->rd_mult_key_qp_fac.num / (double)cfg->rd_mult_key_qp_fac.den; + if (cpi->rd_ctrl.rd_mult_key_qp_fac < 0.25) + cpi->rd_ctrl.rd_mult_key_qp_fac = 0.25; + else if (cpi->rd_ctrl.rd_mult_key_qp_fac > 4.0) + cpi->rd_ctrl.rd_mult_key_qp_fac = 4.0; return VPX_CODEC_OK; } @@ -1956,18 +2037,18 @@ static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { { 0 }, // layer_taget_bitrate 0, // temporal_layering_mode 0, // use_vizier_rc_params - { 0, 1 }, // active_wq_factor - { 0, 1 }, // base_err_per_mb - { 0, 1 }, // sr_default_decay_limit - { 0, 1 }, // sr_diff_factor - { 0, 1 }, // kf_err_per_mb - { 0, 1 }, // kf_frame_min_boost - { 0, 1 }, // kf_frame_max_boost_first - { 0, 1 }, // kf_frame_max_boost_subs - { 0, 1 }, // kf_max_total_boost - { 0, 1 }, // gf_max_total_boost - { 0, 1 }, // gf_frame_max_boost - { 0, 1 }, // zm_factor + { 1, 1 }, // active_wq_factor + { 1, 1 }, // err_per_mb_factor + { 1, 1 }, // sr_default_decay_limit + { 1, 1 }, // sr_diff_factor + { 1, 1 }, // kf_err_per_mb_factor + { 1, 1 }, // kf_frame_min_boost_factor + { 1, 1 }, // kf_frame_max_boost_first_factor + { 1, 1 }, // kf_frame_max_boost_subs_factor + { 1, 1 }, // kf_max_total_boost_factor + { 1, 1 }, // gf_max_total_boost_factor + { 1, 1 }, // gf_frame_max_boost_factor + { 1, 1 }, // zm_factor { 1, 1 }, // rd_mult_inter_qp_fac { 1, 1 }, // rd_mult_arf_qp_fac { 1, 1 }, // rd_mult_key_qp_fac diff --git a/vpx/vpx_encoder.h b/vpx/vpx_encoder.h index 1682931a7..c4589bea1 100644 --- a/vpx/vpx_encoder.h +++ b/vpx/vpx_encoder.h @@ -709,14 +709,14 @@ typedef struct vpx_codec_enc_cfg { */ vpx_rational_t active_wq_factor; - /*!\brief Base error per macroblock. + /*!\brief Error per macroblock adjustment factor. * * Rate control parameters, set from external experiment results. * Only when |use_vizier_rc_params| is set to 1, the pass in value will be * used. Otherwise, the default value is used. * */ - vpx_rational_t base_err_per_mb; + vpx_rational_t err_per_mb_factor; /*!\brief Second reference default decay limit. * @@ -736,68 +736,69 @@ typedef struct vpx_codec_enc_cfg { */ vpx_rational_t sr_diff_factor; - /*!\brief Keyframe error per macroblock. + /*!\brief Keyframe error per macroblock adjustment factor. * * Rate control parameters, set from external experiment results. * Only when |use_vizier_rc_params| is set to 1, the pass in value will be * used. Otherwise, the default value is used. * */ - vpx_rational_t kf_err_per_mb; + vpx_rational_t kf_err_per_mb_factor; - /*!\brief Keyframe minimum boost. + /*!\brief Keyframe minimum boost adjustment factor. * * Rate control parameters, set from external experiment results. * Only when |use_vizier_rc_params| is set to 1, the pass in value will be * used. Otherwise, the default value is used. * */ - vpx_rational_t kf_frame_min_boost; + vpx_rational_t kf_frame_min_boost_factor; - /*!\brief Keyframe maximum boost, for the first keyframe in a chunk. + /*!\brief Keyframe maximum boost adjustment factor, for the first keyframe + * in a chunk. * * Rate control parameters, set from external experiment results. * Only when |use_vizier_rc_params| is set to 1, the pass in value will be * used. Otherwise, the default value is used. * */ - vpx_rational_t kf_frame_max_boost_first; + vpx_rational_t kf_frame_max_boost_first_factor; - /*!\brief Keyframe maximum boost, for subsequent keyframes. + /*!\brief Keyframe maximum boost adjustment factor, for subsequent keyframes. * * Rate control parameters, set from external experiment results. * Only when |use_vizier_rc_params| is set to 1, the pass in value will be * used. Otherwise, the default value is used. * */ - vpx_rational_t kf_frame_max_boost_subs; + vpx_rational_t kf_frame_max_boost_subs_factor; - /*!\brief Keyframe maximum total boost. + /*!\brief Keyframe maximum total boost adjustment factor. * * Rate control parameters, set from external experiment results. * Only when |use_vizier_rc_params| is set to 1, the pass in value will be * used. Otherwise, the default value is used. * */ - vpx_rational_t kf_max_total_boost; + vpx_rational_t kf_max_total_boost_factor; - /*!\brief Golden frame maximum total boost. + /*!\brief Golden frame maximum total boost adjustment factor. * * Rate control parameters, set from external experiment results. * Only when |use_vizier_rc_params| is set to 1, the pass in value will be * used. Otherwise, the default value is used. * */ - vpx_rational_t gf_max_total_boost; + vpx_rational_t gf_max_total_boost_factor; - /*!\brief Golden frame maximum boost. + /*!\brief Golden frame maximum boost adjustment factor. * * Rate control parameters, set from external experiment results. * Only when |use_vizier_rc_params| is set to 1, the pass in value will be * used. Otherwise, the default value is used. * */ - vpx_rational_t gf_frame_max_boost; + vpx_rational_t gf_frame_max_boost_factor; /*!\brief Zero motion power factor. * @@ -292,46 +292,52 @@ static const arg_def_t use_vizier_rc_params = ARG_DEF(NULL, "use-vizier-rc-params", 1, "Use vizier rc params"); static const arg_def_t active_wq_factor = ARG_DEF(NULL, "active-wq-factor", 1, "Active worst quality factor"); -static const arg_def_t base_err_per_mb = - ARG_DEF(NULL, "base-err-per-mb", 1, "Base error per macroblock"); +static const arg_def_t err_per_mb_factor = + ARG_DEF(NULL, "err-per-mb-factor", 1, "Error per macroblock factor"); static const arg_def_t sr_default_decay_limit = ARG_DEF( NULL, "sr-default-decay-limit", 1, "Second reference default decay limit"); static const arg_def_t sr_diff_factor = ARG_DEF(NULL, "sr-diff-factor", 1, "Second reference diff factor"); -static const arg_def_t kf_err_per_mb = - ARG_DEF(NULL, "kf-err-per-mb", 1, "Keyframe error per macroblock"); -static const arg_def_t kf_frame_min_boost = - ARG_DEF(NULL, "kf-frame-min-boost", 1, "Keyframe min boost"); -static const arg_def_t kf_frame_max_boost_first = ARG_DEF( - NULL, "kf-frame-max-boost-first", 1, "Max for the first keyframe boost"); -static const arg_def_t kf_frame_max_boost_subs = ARG_DEF( - NULL, "kf-frame-max-boost-subs", 1, "Max for subsequent keyframe boost"); -static const arg_def_t kf_max_total_boost = - ARG_DEF(NULL, "kf-max-total-boost", 1, "Keyframe max total boost"); -static const arg_def_t gf_max_total_boost = - ARG_DEF(NULL, "gf-max-total-boost", 1, "Golden frame max total boost"); -static const arg_def_t gf_frame_max_boost = - ARG_DEF(NULL, "gf-frame-max-boost", 1, "Golden frame max boost"); +static const arg_def_t kf_err_per_mb_factor = ARG_DEF( + NULL, "kf-err-per-mb-factor", 1, "Keyframe error per macroblock factor"); +static const arg_def_t kf_frame_min_boost_factor = + ARG_DEF(NULL, "kf-frame-min-boost-factor", 1, "Keyframe min boost"); +static const arg_def_t kf_frame_max_boost_first_factor = + ARG_DEF(NULL, "kf-frame-max-boost-first-factor", 1, + "Max keyframe boost adjustment factor for first frame"); +static const arg_def_t kf_frame_max_boost_subs_factor = + ARG_DEF(NULL, "kf-frame-max-boost-subs-factor", 1, + "Max boost adjustment factor for subsequent KFs"); +static const arg_def_t kf_max_total_boost_factor = ARG_DEF( + NULL, "kf-max-total-boost-factor", 1, "Keyframe max total boost factor"); +static const arg_def_t gf_max_total_boost_factor = + ARG_DEF(NULL, "gf-max-total-boost-factor", 1, + "Golden frame max total boost factor"); +static const arg_def_t gf_frame_max_boost_factor = + ARG_DEF(NULL, "gf-frame-max-boost-factor", 1, + "Golden frame max per frame boost factor"); static const arg_def_t zm_factor = ARG_DEF(NULL, "zm-factor", 1, "Zero motion power factor"); static const arg_def_t rd_mult_inter_qp_fac = - ARG_DEF(NULL, "rd-mult-inter-qp-fac", 1, "RD multiplier for inter frames"); + ARG_DEF(NULL, "rd-mult-inter-qp-fac", 1, + "RD multiplier adjustment for inter frames"); static const arg_def_t rd_mult_arf_qp_fac = - ARG_DEF(NULL, "rd-mult-arf-qp-fac", 1, "RD multiplier for alt-ref frames"); -static const arg_def_t rd_mult_key_qp_fac = - ARG_DEF(NULL, "rd-mult-key-qp-fac", 1, "RD multiplier for key frames"); + ARG_DEF(NULL, "rd-mult-arf-qp-fac", 1, + "RD multiplier adjustment for alt-ref frames"); +static const arg_def_t rd_mult_key_qp_fac = ARG_DEF( + NULL, "rd-mult-key-qp-fac", 1, "RD multiplier adjustment for key frames"); static const arg_def_t *vizier_rc_args[] = { &use_vizier_rc_params, &active_wq_factor, - &base_err_per_mb, + &err_per_mb_factor, &sr_default_decay_limit, &sr_diff_factor, - &kf_err_per_mb, - &kf_frame_min_boost, - &kf_frame_max_boost_first, - &kf_frame_max_boost_subs, - &kf_max_total_boost, - &gf_max_total_boost, - &gf_frame_max_boost, + &kf_err_per_mb_factor, + &kf_frame_min_boost_factor, + &kf_frame_max_boost_first_factor, + &kf_frame_max_boost_subs_factor, + &kf_max_total_boost_factor, + &gf_max_total_boost_factor, + &gf_frame_max_boost_factor, &zm_factor, &rd_mult_inter_qp_fac, &rd_mult_arf_qp_fac, @@ -1042,26 +1048,26 @@ static int parse_stream_params(struct VpxEncoderConfig *global, config->cfg.use_vizier_rc_params = arg_parse_int(&arg); } else if (arg_match(&arg, &active_wq_factor, argi)) { config->cfg.active_wq_factor = arg_parse_rational(&arg); - } else if (arg_match(&arg, &base_err_per_mb, argi)) { - config->cfg.base_err_per_mb = arg_parse_rational(&arg); + } else if (arg_match(&arg, &err_per_mb_factor, argi)) { + config->cfg.err_per_mb_factor = arg_parse_rational(&arg); } else if (arg_match(&arg, &sr_default_decay_limit, argi)) { config->cfg.sr_default_decay_limit = arg_parse_rational(&arg); } else if (arg_match(&arg, &sr_diff_factor, argi)) { config->cfg.sr_diff_factor = arg_parse_rational(&arg); - } else if (arg_match(&arg, &kf_err_per_mb, argi)) { - config->cfg.kf_err_per_mb = arg_parse_rational(&arg); - } else if (arg_match(&arg, &kf_frame_min_boost, argi)) { - config->cfg.kf_frame_min_boost = arg_parse_rational(&arg); - } else if (arg_match(&arg, &kf_frame_max_boost_first, argi)) { - config->cfg.kf_frame_max_boost_first = arg_parse_rational(&arg); - } else if (arg_match(&arg, &kf_frame_max_boost_subs, argi)) { - config->cfg.kf_frame_max_boost_subs = arg_parse_rational(&arg); - } else if (arg_match(&arg, &kf_max_total_boost, argi)) { - config->cfg.kf_max_total_boost = arg_parse_rational(&arg); - } else if (arg_match(&arg, &gf_max_total_boost, argi)) { - config->cfg.gf_max_total_boost = arg_parse_rational(&arg); - } else if (arg_match(&arg, &gf_frame_max_boost, argi)) { - config->cfg.gf_frame_max_boost = arg_parse_rational(&arg); + } else if (arg_match(&arg, &kf_err_per_mb_factor, argi)) { + config->cfg.kf_err_per_mb_factor = arg_parse_rational(&arg); + } else if (arg_match(&arg, &kf_frame_min_boost_factor, argi)) { + config->cfg.kf_frame_min_boost_factor = arg_parse_rational(&arg); + } else if (arg_match(&arg, &kf_frame_max_boost_first_factor, argi)) { + config->cfg.kf_frame_max_boost_first_factor = arg_parse_rational(&arg); + } else if (arg_match(&arg, &kf_frame_max_boost_subs_factor, argi)) { + config->cfg.kf_frame_max_boost_subs_factor = arg_parse_rational(&arg); + } else if (arg_match(&arg, &kf_max_total_boost_factor, argi)) { + config->cfg.kf_max_total_boost_factor = arg_parse_rational(&arg); + } else if (arg_match(&arg, &gf_max_total_boost_factor, argi)) { + config->cfg.gf_max_total_boost_factor = arg_parse_rational(&arg); + } else if (arg_match(&arg, &gf_frame_max_boost_factor, argi)) { + config->cfg.gf_frame_max_boost_factor = arg_parse_rational(&arg); } else if (arg_match(&arg, &zm_factor, argi)) { config->cfg.zm_factor = arg_parse_rational(&arg); } else if (arg_match(&arg, &rd_mult_inter_qp_fac, argi)) { |