shithub: libvpx

Download patch

ref: 99df6bb62959bfda82c0d636105d8239f147715a
parent: 82733643ca27bd63de4ea8d696d971cec213e20b
author: Paul Wilkins <paulwilkins@google.com>
date: Thu Nov 24 13:25:03 EST 2011

Further work on extended Q range.

Fixed bug in firspass.c call to vp8_initialize_rd_consts()

This was passing in vp8_dc_quant(cm->base_qindex, cm->y1dc_delta_q)
 instead of (cm->base_qindex + cm->y1dc_delta_q).

It just so happens that for the value 26 used for cm->base_qindex in the
unextended Q case,  the two give similar results. However, when using
the extended Q range the two are very different.

Also added more stats output and partly disabled another broken feature.

Change-Id: Iddf6cf5ea8467c44b7c133f38e629f6ba6f2581e

--- a/vp8/common/quant_common.c
+++ b/vp8/common/quant_common.c
@@ -102,8 +102,8 @@
 
     QIndex = QIndex + Delta;
 
-    if (QIndex > 117)
-        QIndex = 117;
+    if (QIndex > 127)
+        QIndex = 127;
     else if (QIndex < 0)
         QIndex = 0;
 
--- a/vp8/encoder/firstpass.c
+++ b/vp8/encoder/firstpass.c
@@ -535,7 +535,7 @@
     //if ( 0 )
     {
         int flag[2] = {1, 1};
-        vp8_initialize_rd_consts(cpi, vp8_dc_quant(cm->base_qindex, cm->y1dc_delta_q));
+        vp8_initialize_rd_consts(cpi, cm->base_qindex + cm->y1dc_delta_q);
         vpx_memcpy(cm->fc.mvc, vp8_default_mv_context, sizeof(vp8_default_mv_context));
         vp8_build_component_cost_table(cpi->mb.mvcost, (const MV_CONTEXT *) cm->fc.mvc, flag);
     }
@@ -895,8 +895,8 @@
     double error_term = err_per_mb / err_devisor;
     double correction_factor;
 
-    // Adjustment based on Q to power term.
-    power_term = pt_low + (Q * 0.01);
+    // Adjustment based on actual quantizer to power term.
+    power_term = (vp8_convert_qindex_to_q(Q) * 0.01) + 0.36;
     power_term = (power_term > pt_high) ? pt_high : power_term;
 
     // Adjustments to error term
@@ -973,6 +973,7 @@
 
     // Estimate of overhead bits per mb
     // Correction to overhead bits for min allowed Q.
+    // PGW TODO.. This code is broken for the extended Q range
     overhead_bits_per_mb = overhead_bits / num_mbs;
     overhead_bits_per_mb *= pow( 0.98, (double)cpi->twopass.maxq_min_limit );
 
@@ -1013,7 +1014,8 @@
     // Adjust maxq_min_limit and maxq_max_limit limits based on
     // averaga q observed in clip for non kf/gf.arf frames
     // Give average a chance to settle though.
-    if ( (cpi->ni_frames >
+    // PGW TODO.. This code is broken for the extended Q range
+    /*if ( (cpi->ni_frames >
                   ((unsigned int)cpi->twopass.total_stats->count >> 8)) &&
          (cpi->ni_frames > 150) )
     {
@@ -1021,7 +1023,7 @@
                                   ? (cpi->ni_av_qi + 32) : cpi->worst_quality;
         cpi->twopass.maxq_min_limit = ((cpi->ni_av_qi - 32) > cpi->best_quality)
                                   ? (cpi->ni_av_qi - 32) : cpi->best_quality;
-    }
+    }*/
 
     return Q;
 }
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -4645,8 +4645,9 @@
         vp8_clear_system_state();  //__asm emms;
 
         if (cpi->twopass.total_left_stats->coded_error != 0.0)
-            fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %6d %6d"
-                       "%6d %6d %6d %5d %5d %5d %8d %8.2f %10d %10.3f"
+            fprintf(f, "%10d %10d %10d %10d %10d %10d %10d"
+                       "%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f"
+                       "%6d %5d %5d %5d %8d %8.2f %10d %10.3f"
                        "%10.3f %8d\n",
                        cpi->common.current_video_frame, cpi->this_frame_target,
                        cpi->projected_frame_size,
@@ -4653,9 +4654,17 @@
                        (cpi->projected_frame_size - cpi->this_frame_target),
                        (int)cpi->total_target_vs_actual,
                        (cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
-                       (int)cpi->total_actual_bits, cm->base_qindex,
-                       cpi->active_best_quality, cpi->active_worst_quality,
-                       cpi->ni_av_qi, cpi->cq_target_quality,
+                       (int)cpi->total_actual_bits,
+                       vp8_convert_qindex_to_q(cm->base_qindex),
+#if CONFIG_EXTEND_QRANGE
+                        (double)vp8_dc_quant(cm->base_qindex,0)/4.0,
+#else
+                        (double)vp8_dc_quant(cm->base_qindex,0),
+#endif
+                       vp8_convert_qindex_to_q(cpi->active_best_quality),
+                       vp8_convert_qindex_to_q(cpi->active_worst_quality),
+                       vp8_convert_qindex_to_q(cpi->ni_av_qi),
+                       vp8_convert_qindex_to_q(cpi->cq_target_quality),
                        cpi->zbin_over_quant,
                        //cpi->avg_frame_qindex, cpi->zbin_over_quant,
                        cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
@@ -4667,8 +4676,9 @@
                            cpi->twopass.total_left_stats->coded_error,
                        cpi->tot_recode_hits);
         else
-            fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %6d %6d"
-                       "%6d %6d %6d %5d %5d %5d %8d %8.2f %10d %10.3f"
+            fprintf(f, "%10d %10d %10d %10d %10d %10d %10d"
+                       "%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f"
+                       "%6d %5d %5d %5d %8d %8.2f %10d %10.3f"
                        "%8d\n",
                        cpi->common.current_video_frame,
                        cpi->this_frame_target, cpi->projected_frame_size,
@@ -4675,9 +4685,17 @@
                        (cpi->projected_frame_size - cpi->this_frame_target),
                        (int)cpi->total_target_vs_actual,
                        (cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
-                       (int)cpi->total_actual_bits, cm->base_qindex,
-                       cpi->active_best_quality, cpi->active_worst_quality,
-                       cpi->ni_av_qi, cpi->cq_target_quality,
+                       (int)cpi->total_actual_bits,
+                       vp8_convert_qindex_to_q(cm->base_qindex),
+#if CONFIG_EXTEND_QRANGE
+                        (double)vp8_dc_quant(cm->base_qindex,0)/4.0,
+#else
+                        (double)vp8_dc_quant(cm->base_qindex,0),
+#endif
+                       vp8_convert_qindex_to_q(cpi->active_best_quality),
+                       vp8_convert_qindex_to_q(cpi->active_worst_quality),
+                       vp8_convert_qindex_to_q(cpi->ni_av_qi),
+                       vp8_convert_qindex_to_q(cpi->cq_target_quality),
                        cpi->zbin_over_quant,
                        //cpi->avg_frame_qindex, cpi->zbin_over_quant,
                        cm->refresh_golden_frame, cm->refresh_alt_ref_frame,
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -255,8 +255,6 @@
     if (q < 8)
         q = 8;
 
-
-
 #if CONFIG_EXTEND_QRANGE
     cpi->RDMULT *= 16;
 #endif
--