shithub: libvpx

Download patch

ref: a40cb691b6bec1fe69cca7818d91a1c77274da33
parent: 06fee5a89b7729cc178180e9c6743138faba7e79
parent: ab4383063c79e558ee5d8c8140d38626825ebfec
author: Paul Wilkins <paulwilkins@google.com>
date: Wed Apr 7 08:52:47 EDT 2021

Merge "Change  zm_factor for Vizier."

--- a/vp8/vp8_cx_iface.c
+++ b/vp8/vp8_cx_iface.c
@@ -268,7 +268,7 @@
   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, zm_power_factor.den, 1, 1000);
+  RANGE_CHECK(cfg, zm_factor.den, 1, 1000);
 
   return VPX_CODEC_OK;
 }
@@ -1313,7 +1313,7 @@
         { 0, 1 }, /* kf_max_total_boost */
         { 0, 1 }, /* gf_max_total_boost */
         { 0, 1 }, /* gf_frame_max_boost */
-        { 0, 1 }, /* zm_power_factor */
+        { 0, 1 }, /* zm_factor */
     } },
 };
 
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -73,7 +73,7 @@
 #define MAX_KF_TOT_BOOST 5400
 #endif
 
-#define ZM_POWER_FACTOR 0.75
+#define DEFAULT_ZM_FACTOR 0.5
 #define MINQ_ADJ_LIMIT 48
 #define MINQ_ADJ_LIMIT_CQ 20
 #define HIGH_UNDERSHOOT_RATIO 2
@@ -1878,10 +1878,18 @@
 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);
-  const double zero_motion_factor =
-      (0.95 * pow((frame_stats->pcnt_inter - frame_stats->pcnt_motion),
-                  twopass->zm_power_factor));
+  double zero_motion_factor =
+      twopass->zm_factor * DEFAULT_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
+  // here just in case.
+  if (zero_motion_factor > 1.0)
+    zero_motion_factor = 1.0;
+  else if (zero_motion_factor < 0.0)
+    zero_motion_factor = 0.0;
+
   return VPXMAX(zero_motion_factor,
                 (sr_decay_rate + ((1.0 - sr_decay_rate) * zero_motion_factor)));
 }
@@ -3501,7 +3509,7 @@
     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_power_factor = ZM_POWER_FACTOR;
+    twopass->zm_factor = 1.0;
   } else {
     // Vizer experimental parameters from training.
     // Later these will be set via the command line.
@@ -3517,7 +3525,7 @@
       twopass->kf_frame_max_boost_first = 25.5;
       twopass->kf_frame_max_boost_subs = twopass->kf_frame_max_boost_first;
       twopass->kf_max_total_boost = MAX_KF_TOT_BOOST;
-      twopass->zm_power_factor = 2.93715229184991;
+      twopass->zm_factor = 1.0;
     } else if (screen_area <= 320 * 240) {
       twopass->active_wq_factor = 55.0;
       twopass->base_err_per_mb = 34525.33177195309;
@@ -3530,7 +3538,7 @@
       twopass->kf_frame_max_boost_first = 185.0;
       twopass->kf_frame_max_boost_subs = twopass->kf_frame_max_boost_first;
       twopass->kf_max_total_boost = MAX_KF_TOT_BOOST;
-      twopass->zm_power_factor = 3.5299221493593413;
+      twopass->zm_factor = 1.0;
     } else if (screen_area <= 640 * 360) {
       twopass->active_wq_factor = 12.5;
       twopass->base_err_per_mb = 18823.978018028298;
@@ -3543,7 +3551,7 @@
       twopass->kf_frame_max_boost_first = 224.5;
       twopass->kf_frame_max_boost_subs = twopass->kf_frame_max_boost_first;
       twopass->kf_max_total_boost = MAX_KF_TOT_BOOST;
-      twopass->zm_power_factor = 2.265742666649307;
+      twopass->zm_factor = 1.0;
     } else if (screen_area <= 854 * 480) {
       twopass->active_wq_factor = 51.5;
       twopass->base_err_per_mb = 33718.98307662595;
@@ -3556,7 +3564,7 @@
       twopass->kf_frame_max_boost_first = 28.0;
       twopass->kf_frame_max_boost_subs = twopass->kf_frame_max_boost_first;
       twopass->kf_max_total_boost = MAX_KF_TOT_BOOST;
-      twopass->zm_power_factor = 3.552278528517416;
+      twopass->zm_factor = 1.0;
     } else if (screen_area <= 1280 * 720) {
       twopass->active_wq_factor = 41.5;
       twopass->base_err_per_mb = 29527.46375825401;
@@ -3569,7 +3577,7 @@
       twopass->kf_frame_max_boost_first = 53.0;
       twopass->kf_frame_max_boost_subs = twopass->kf_frame_max_boost_first;
       twopass->kf_max_total_boost = MAX_KF_TOT_BOOST;
-      twopass->zm_power_factor = 2.568627575572356;
+      twopass->zm_factor = 1.0;
     } else {
       twopass->active_wq_factor = 31.0;
       twopass->base_err_per_mb = 34474.723463367416;
@@ -3582,7 +3590,7 @@
       twopass->kf_frame_max_boost_first = 419.5;
       twopass->kf_frame_max_boost_subs = twopass->kf_frame_max_boost_first;
       twopass->kf_max_total_boost = MAX_KF_TOT_BOOST;
-      twopass->zm_power_factor = 5.5776463538431935;
+      twopass->zm_factor = 1.0;
     }
   }
 }
--- a/vp9/encoder/vp9_firstpass.h
+++ b/vp9/encoder/vp9_firstpass.h
@@ -234,7 +234,7 @@
   int kf_max_total_boost;
   int gf_max_total_boost;
   double gf_frame_max_boost;
-  double zm_power_factor;
+  double zm_factor;
 } TWO_PASS;
 
 struct VP9_COMP;
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -360,7 +360,7 @@
   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, zm_power_factor.den, 1, 1000);
+  RANGE_CHECK(cfg, zm_factor.den, 1, 1000);
 
   return VPX_CODEC_OK;
 }
@@ -681,8 +681,8 @@
                                           (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;
-  cpi->twopass.zm_power_factor =
-      (double)cfg->zm_power_factor.num / (double)cfg->zm_power_factor.den;
+  cpi->twopass.zm_factor =
+      (double)cfg->zm_factor.num / (double)cfg->zm_factor.den;
 
   return VPX_CODEC_OK;
 }
@@ -1954,7 +1954,7 @@
         { 0, 1 },  // kf_max_total_boost
         { 0, 1 },  // gf_max_total_boost
         { 0, 1 },  // gf_frame_max_boost
-        { 0, 1 },  // zm_power_factor
+        { 0, 1 },  // zm_factor
     } },
 };
 
--- a/vpx/vpx_encoder.h
+++ b/vpx/vpx_encoder.h
@@ -776,7 +776,7 @@
    * Rate control parameters, set from external experiment results.
    *
    */
-  vpx_rational_t zm_power_factor;
+  vpx_rational_t zm_factor;
 } vpx_codec_enc_cfg_t; /**< alias for struct vpx_codec_enc_cfg */
 
 /*!\brief  vp9 svc extra configure parameters
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -310,7 +310,7 @@
     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 zm_power_factor =
+static const arg_def_t zm_factor =
     ARG_DEF(NULL, "zm-power-factor", 1, "Zero motion power factor");
 static const arg_def_t *vizier_rc_args[] = { &active_wq_factor,
                                              &base_err_per_mb,
@@ -323,7 +323,7 @@
                                              &kf_max_total_boost,
                                              &gf_max_total_boost,
                                              &gf_frame_max_boost,
-                                             &zm_power_factor,
+                                             &zm_factor,
                                              NULL };
 #endif
 
@@ -1048,8 +1048,8 @@
       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, &zm_power_factor, argi)) {
-      config->cfg.zm_power_factor = arg_parse_rational(&arg);
+    } else if (arg_match(&arg, &zm_factor, argi)) {
+      config->cfg.zm_factor = arg_parse_rational(&arg);
 #endif
 #if CONFIG_VP9_HIGHBITDEPTH
     } else if (arg_match(&arg, &test16bitinternalarg, argi)) {