]> granicus.if.org Git - libvpx/commitdiff
Fix to avoid abrupt relaxation of max qindex in recode path
authorRanjit Kumar Tulabandu <ranjit.tulabandu@ittiam.com>
Wed, 4 Jan 2017 12:12:01 +0000 (17:42 +0530)
committerRanjit Kumar Tulabandu <ranjit.tulabandu@ittiam.com>
Mon, 16 Jan 2017 12:33:27 +0000 (18:03 +0530)
The fix relaxes the max qindex based on the data from previous loop of
coding if output frame size is greater than maximum frame size allowed

Change-Id: Iac1f63ec67559d68766e090a7cbb80b812b2560f

vp9/encoder/vp9_encoder.c
vp9/encoder/vp9_ratectrl.c
vp9/encoder/vp9_ratectrl.h

index 147f97004f3ca3de4932f51112a42053129939ad..1e283aac09285deb8d7ba9e63b3fe973586ddbb6 100644 (file)
@@ -3792,8 +3792,14 @@ static void encode_with_recode_loop(VP9_COMP *cpi,
         // Frame is too large
         if (rc->projected_frame_size > rc->this_frame_target) {
           // Special case if the projected size is > the max allowed.
-          if (rc->projected_frame_size >= rc->max_frame_bandwidth)
-            q_high = rc->worst_quality;
+          if (rc->projected_frame_size >= rc->max_frame_bandwidth) {
+            double q_val_high;
+            q_val_high = vp9_convert_qindex_to_q(q_high, cm->bit_depth);
+            q_val_high = q_val_high * ((double)rc->projected_frame_size /
+                                       rc->max_frame_bandwidth);
+            q_high = vp9_convert_q_to_qindex(q_val_high, cm->bit_depth);
+            q_high = clamp(q_high, rc->best_quality, rc->worst_quality);
+          }
 
           // Raise Qlow as to at least the current value
           q_low = q < q_high ? q + 1 : q_high;
index b45f8d0d9db044cc75874723123dea87758cfdb1..bb95f7c31c36ab3476263bdc87cf8c9e1cd632db 100644 (file)
@@ -174,6 +174,19 @@ double vp9_convert_qindex_to_q(int qindex, vpx_bit_depth_t bit_depth) {
 #endif
 }
 
+int vp9_convert_q_to_qindex(double q_val, vpx_bit_depth_t bit_depth) {
+  int i;
+
+  for (i = 0; i < QINDEX_RANGE; ++i)
+    if (vp9_convert_qindex_to_q(i, bit_depth) >= q_val)
+      break;
+
+  if (i == QINDEX_RANGE)
+    i--;
+
+  return i;
+}
+
 int vp9_rc_bits_per_mb(FRAME_TYPE frame_type, int qindex,
                        double correction_factor,
                        vpx_bit_depth_t bit_depth) {
index 7024bcfa9607249b98a3f4bfa33bb1be0e32e806..a35675bbd164feb466951c29ca69dc0bb2ad280b 100644 (file)
@@ -177,6 +177,8 @@ int vp9_estimate_bits_at_q(FRAME_TYPE frame_kind, int q, int mbs,
 
 double vp9_convert_qindex_to_q(int qindex, vpx_bit_depth_t bit_depth);
 
+int vp9_convert_q_to_qindex(double q_val, vpx_bit_depth_t bit_depth);
+
 void vp9_rc_init_minq_luts(void);
 
 int vp9_rc_get_default_min_gf_interval(int width, int height, double framerate);