Pass vizier rd parameter values
authorCheng Chen <chengchen@google.com>
Thu, 15 Apr 2021 05:15:54 +0000 (22:15 -0700)
committerCheng Chen <chengchen@google.com>
Thu, 15 Apr 2021 05:49:51 +0000 (22:49 -0700)
Add command line options for three rd parameters.
They are controlled by --use_vizier_rc_params, together with
other rc parameters.
If not set from command line, current default values will be used.

Change-Id: Ie1b9a98a50326551cc1d5940c4b637cb01a61aa0

vp8/vp8_cx_iface.c
vp9/encoder/vp9_rd.c
vp9/vp9_cx_iface.c
vpx/vpx_encoder.h
vpxenc.c

index 64d01e5..872710f 100644 (file)
@@ -270,6 +270,9 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
   RANGE_CHECK(cfg, gf_max_total_boost.den, 1, 1000);
   RANGE_CHECK(cfg, gf_frame_max_boost.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);
+  RANGE_CHECK(cfg, rd_mult_key_qp_fac.den, 1, 1000);
 
   return VPX_CODEC_OK;
 }
@@ -1316,6 +1319,9 @@ static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] = {
         { 0, 1 }, /* gf_max_total_boost */
         { 0, 1 }, /* gf_frame_max_boost */
         { 0, 1 }, /* zm_factor */
+        { 1, 1 }, /* rd_mult_inter_qp_fac */
+        { 1, 1 }, /* rd_mult_arf_qp_fac */
+        { 1, 1 }, /* rd_mult_key_qp_fac */
     } },
 };
 
index 87b9a69..9fa3ff1 100644 (file)
@@ -202,40 +202,19 @@ static const int rd_frame_type_factor[FRAME_UPDATE_TYPES] = { 128, 144, 128,
 void vp9_init_rd_parameters(VP9_COMP *cpi) {
   RD_CONTROL *const rdc = &cpi->rd_ctrl;
 
+  // When |use_vizier_rc_params| is 1, we expect the rd parameters have been
+  // initialized by the pass in values.
+  // Be careful that parameters below are only initialized to 1, if we do not
+  // pass values to them. It is desired to take care of each parameter when
+  // using |use_vizier_rc_params|.
+  if (cpi->twopass.use_vizier_rc_params) return;
+
   // Make sure this function is floating point safe.
   vpx_clear_system_state();
 
-  rdc->rd_mult_arf_qp_fac = 1.0;  // Default: No Vizier values yet
-
-  // These hard wired estimates for the Vizier values will be removed later
-  // as the per format factors will be set on the command line.
-  if (0) {
-    unsigned int screen_area = (cpi->common.width * cpi->common.height);
-
-    if (screen_area <= 176 * 144) {
-      rdc->rd_mult_inter_qp_fac = 0.896;
-      rdc->rd_mult_key_qp_fac = 1.050;
-    } else if (screen_area <= 320 * 240) {
-      rdc->rd_mult_inter_qp_fac = 0.998;
-      rdc->rd_mult_key_qp_fac = 0.952;
-    } else if (screen_area <= 640 * 360) {
-      rdc->rd_mult_inter_qp_fac = 0.959;
-      rdc->rd_mult_key_qp_fac = 1.071;
-    } else if (screen_area <= 854 * 480) {
-      rdc->rd_mult_inter_qp_fac = 1.027;
-      rdc->rd_mult_key_qp_fac = 1.280;
-    } else if (screen_area <= 1280 * 720) {
-      rdc->rd_mult_inter_qp_fac = 1.004;
-      rdc->rd_mult_key_qp_fac = 1.193;
-    } else {
-      rdc->rd_mult_inter_qp_fac = 0.874;
-      rdc->rd_mult_key_qp_fac = 0.837;
-    }
-  } else {
-    // For now force defaults unless testing
-    rdc->rd_mult_inter_qp_fac = 1.0;
-    rdc->rd_mult_key_qp_fac = 1.0;
-  }
+  rdc->rd_mult_inter_qp_fac = 1.0;
+  rdc->rd_mult_arf_qp_fac = 1.0;
+  rdc->rd_mult_key_qp_fac = 1.0;
 }
 
 // Returns the default rd multiplier for inter frames for a given qindex.
index e35b6f1..c2ca215 100644 (file)
@@ -362,6 +362,9 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
   RANGE_CHECK(cfg, gf_max_total_boost.den, 1, 1000);
   RANGE_CHECK(cfg, gf_frame_max_boost.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);
+  RANGE_CHECK(cfg, rd_mult_key_qp_fac.den, 1, 1000);
 
   return VPX_CODEC_OK;
 }
@@ -686,6 +689,12 @@ static vpx_codec_err_t set_twopass_params_from_config(
       (double)cfg->gf_frame_max_boost.num / (double)cfg->gf_frame_max_boost.den;
   cpi->twopass.zm_factor =
       (double)cfg->zm_factor.num / (double)cfg->zm_factor.den;
+  cpi->rd_ctrl.rd_mult_inter_qp_fac = (double)cfg->rd_mult_inter_qp_fac.num /
+                                      (double)cfg->rd_mult_inter_qp_fac.den;
+  cpi->rd_ctrl.rd_mult_arf_qp_fac =
+      (double)cfg->rd_mult_arf_qp_fac.num / (double)cfg->rd_mult_arf_qp_fac.den;
+  cpi->rd_ctrl.rd_mult_key_qp_fac =
+      (double)cfg->rd_mult_key_qp_fac.num / (double)cfg->rd_mult_key_qp_fac.den;
 
   return VPX_CODEC_OK;
 }
@@ -1959,6 +1968,9 @@ static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = {
         { 0, 1 },  // gf_max_total_boost
         { 0, 1 },  // gf_frame_max_boost
         { 0, 1 },  // zm_factor
+        { 1, 1 },  // rd_mult_inter_qp_fac
+        { 1, 1 },  // rd_mult_arf_qp_fac
+        { 1, 1 },  // rd_mult_key_qp_fac
     } },
 };
 
index 3c9304b..255cb69 100644 (file)
@@ -807,6 +807,36 @@ typedef struct vpx_codec_enc_cfg {
    *
    */
   vpx_rational_t zm_factor;
+
+  /*!\brief Rate-distortion multiplier for inter frames.
+   * The multiplier is a crucial parameter in the calculation of rate distortion
+   * cost. It is often related to the qp (qindex) value.
+   * Rate control parameters, could be 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 rd_mult_inter_qp_fac;
+
+  /*!\brief Rate-distortion multiplier for alt-ref frames.
+   * The multiplier is a crucial parameter in the calculation of rate distortion
+   * cost. It is often related to the qp (qindex) value.
+   * Rate control parameters, could be 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 rd_mult_arf_qp_fac;
+
+  /*!\brief Rate-distortion multiplier for key frames.
+   * The multiplier is a crucial parameter in the calculation of rate distortion
+   * cost. It is often related to the qp (qindex) value.
+   * Rate control parameters, could be 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 rd_mult_key_qp_fac;
 } vpx_codec_enc_cfg_t; /**< alias for struct vpx_codec_enc_cfg */
 
 /*!\brief  vp9 svc extra configure parameters
index c9e386a..1a2b4a9 100644 (file)
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -314,6 +314,12 @@ 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 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");
+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");
 static const arg_def_t *vizier_rc_args[] = { &use_vizier_rc_params,
                                              &active_wq_factor,
                                              &base_err_per_mb,
@@ -327,6 +333,9 @@ static const arg_def_t *vizier_rc_args[] = { &use_vizier_rc_params,
                                              &gf_max_total_boost,
                                              &gf_frame_max_boost,
                                              &zm_factor,
+                                             &rd_mult_inter_qp_fac,
+                                             &rd_mult_arf_qp_fac,
+                                             &rd_mult_key_qp_fac,
                                              NULL };
 #endif
 
@@ -1055,6 +1064,12 @@ static int parse_stream_params(struct VpxEncoderConfig *global,
       config->cfg.gf_frame_max_boost = 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)) {
+      config->cfg.rd_mult_inter_qp_fac = arg_parse_rational(&arg);
+    } else if (arg_match(&arg, &rd_mult_arf_qp_fac, argi)) {
+      config->cfg.rd_mult_arf_qp_fac = arg_parse_rational(&arg);
+    } else if (arg_match(&arg, &rd_mult_key_qp_fac, argi)) {
+      config->cfg.rd_mult_key_qp_fac = arg_parse_rational(&arg);
 #endif
 #if CONFIG_VP9_HIGHBITDEPTH
     } else if (arg_match(&arg, &test16bitinternalarg, argi)) {