shithub: libvpx

Download patch

ref: f32829a2e5db3cd1624e8a7a530af84c382762ef
parent: c19de35ed2b772fd21092c727c5e090034876d4f
author: Cheng Chen <chengchen@google.com>
date: Tue Mar 16 18:42:40 EDT 2021

Pass vizier rc parameter values from command line to twopass

Change-Id: I02eabeccf2fe4604875820d38e23c2586a63e290

--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -638,6 +638,41 @@
   return VPX_CODEC_OK;
 }
 
+static vpx_codec_err_t set_twopass_params_from_config(
+    const vpx_codec_enc_cfg_t *const cfg, struct VP9_COMP *cpi) {
+  if (cpi == NULL) return VPX_CODEC_ERROR;
+
+  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;
+  cpi->twopass.sr_default_decay_limit =
+      (double)cfg->sr_default_decay_limit.num /
+      (double)cfg->sr_default_decay_limit.den;
+  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;
+  cpi->twopass.kf_frame_max_boost_first =
+      (double)cfg->kf_frame_max_boost_first.num /
+      (double)cfg->kf_frame_max_boost_first.den;
+  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;
+  cpi->twopass.zm_power_factor =
+      (double)cfg->zm_power_factor.num / (double)cfg->zm_power_factor.den;
+
+  return VPX_CODEC_OK;
+}
+
 static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx,
                                           const vpx_codec_enc_cfg_t *cfg) {
   vpx_codec_err_t res;
@@ -664,6 +699,7 @@
   if (res == VPX_CODEC_OK) {
     ctx->cfg = *cfg;
     set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
+    set_twopass_params_from_config(&ctx->cfg, ctx->cpi);
     // On profile change, request a key frame
     force_key |= ctx->cpi->common.profile != ctx->oxcf.profile;
     vp9_change_config(ctx->cpi, &ctx->oxcf);
@@ -696,6 +732,7 @@
   if (res == VPX_CODEC_OK) {
     ctx->extra_cfg = *extra_cfg;
     set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
+    set_twopass_params_from_config(&ctx->cfg, ctx->cpi);
     vp9_change_config(ctx->cpi, &ctx->oxcf);
   }
   return res;
@@ -940,6 +977,7 @@
 #endif
       priv->cpi = vp9_create_compressor(&priv->oxcf, priv->buffer_pool);
       if (priv->cpi == NULL) res = VPX_CODEC_MEM_ERROR;
+      set_twopass_params_from_config(&priv->cfg, priv->cpi);
     }
   }