shithub: libvpx

Download patch

ref: 1ca39bf26dd114f224ce67f1f3f85076cdafaacc
parent: f1a3b1e0d94dec2d40008f36fdfad99338484b9a
author: Paul Wilkins <paulwilkins@google.com>
date: Tue Jun 29 08:15:54 EDT 2010

Further adjustment of RD behaviour with Q and Zbin.

Following conversations with Tim T (Derf) I ran a large number of
tests comparing the existing polynomial expression with a simpler
^2 variant. Though the polynomial was sometimes a little better at
the extremes of Q it was possible to get close for most clips and
even a little better on some.

This code also changes the way the RD multiplier is calculated
when the ZBIN is extended to use a variant of the same ^2
expression.

I hope that this simpler expression will be easier to tune further
as we expand our test set and consider adjustments based on content.

Change-Id: I73b2564346e74d1332c33e2c1964ae093437456c

--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -231,19 +231,30 @@
     int i;
     int *thresh;
     int threshmult;
+    double capped_q = (Qvalue < 160) ? (double)Qvalue : 160.0;
+    double rdconst = 3.00;
 
-    int capped_q = (Qvalue < 160) ? Qvalue : 160;
-
     vp8_clear_system_state();  //__asm emms;
 
-    cpi->RDMULT = (int)( (0.0001 * (capped_q * capped_q * capped_q * capped_q))
-                        -(0.015 * (capped_q * capped_q * capped_q))
-                        +(3.25 * (capped_q * capped_q))
-                        -(17.5 * capped_q) + 125.0);
+    // Further tests required to see if optimum is different
+    // for key frames, golden frames and arf frames.
+    // if (cpi->common.refresh_golden_frame ||
+    //     cpi->common.refresh_alt_ref_frame)
+    cpi->RDMULT = (int)(rdconst * (capped_q * capped_q));
 
-    if (cpi->RDMULT < 125)
-        cpi->RDMULT = 125;
+    // Extend rate multiplier along side quantizer zbin increases
+    if (cpi->zbin_over_quant  > 0)
+    {
+        double oq_factor;
+        double modq;
 
+        // Experimental code using the same basic equation as used for Q above
+        // The units of cpi->zbin_over_quant are 1/128 of Q bin size
+        oq_factor = 1.0 + ((double)0.0015625 * cpi->zbin_over_quant);
+        modq = (int)((double)capped_q * oq_factor);
+        cpi->RDMULT = (int)(rdconst * (modq * modq));
+    }
+
     if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME))
     {
         if (cpi->next_iiratio > 31)
@@ -252,17 +263,8 @@
             cpi->RDMULT += (cpi->RDMULT * rd_iifactor[cpi->next_iiratio]) >> 4;
     }
 
-
-    // Extend rate multiplier along side quantizer zbin increases
-    if (cpi->zbin_over_quant  > 0)
-    {
-        double oq_factor = pow(1.006,  cpi->zbin_over_quant);
-
-        if (oq_factor > (1.0 + ((double)cpi->zbin_over_quant / 64.0)))
-            oq_factor = (1.0 + (double)cpi->zbin_over_quant / 64.0);
-
-        cpi->RDMULT = (int)(oq_factor * cpi->RDMULT);
-    }
+    if (cpi->RDMULT < 125)
+        cpi->RDMULT = 125;
 
     cpi->mb.errorperbit = (cpi->RDMULT / 100);