]> granicus.if.org Git - libvpx/commitdiff
Increase the bits allocated to key frame
authorDeepa K G <deepa.kg@ittiam.com>
Fri, 17 May 2019 10:35:06 +0000 (16:05 +0530)
committerDeepa K G <deepa.kg@ittiam.com>
Tue, 21 May 2019 06:45:43 +0000 (12:15 +0530)
Based on the spatial complexity, increase the
bits allocated to key frame.

Change-Id: I4f96990a13bcc3bdb7a22d50e67e2bd622f1ff7b

vp9/encoder/vp9_firstpass.c
vpx_dsp/vpx_dsp_common.h

index 0521daf1f2db934c11475391591852b4876718b4..353b397d30c9715d1bd13d39fe119cbbbd5effa9 100644 (file)
@@ -2925,6 +2925,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
   FIRSTPASS_STATS next_frame;
   FIRSTPASS_STATS last_frame;
   int kf_bits = 0;
+  int64_t max_kf_bits;
   double decay_accumulator = 1.0;
   double zero_motion_accumulator = 1.0;
   double zero_motion_sum = 0.0;
@@ -3175,6 +3176,13 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
   // Work out how many bits to allocate for the key frame itself.
   kf_bits = calculate_boost_bits((rc->frames_to_key - 1), rc->kf_boost,
                                  twopass->kf_group_bits);
+  // Based on the spatial complexity, increase the bits allocated to key frame.
+  kf_bits +=
+      (int)((twopass->kf_group_bits - kf_bits) * (kf_mod_err / kf_group_err));
+  max_kf_bits =
+      twopass->kf_group_bits - (rc->frames_to_key - 1) * FRAME_OVERHEAD_BITS;
+  max_kf_bits = lclamp(max_kf_bits, 0, INT_MAX);
+  kf_bits = VPXMIN(kf_bits, (int)max_kf_bits);
 
   twopass->kf_group_bits -= kf_bits;
 
index f1fcf2df5ff949573900d95041805170526dbd6f..2de4495465e39d3085a45942e7cb49f6f6ff1b6c 100644 (file)
@@ -57,6 +57,10 @@ static INLINE double fclamp(double value, double low, double high) {
   return value < low ? low : (value > high ? high : value);
 }
 
+static INLINE int64_t lclamp(int64_t value, int64_t low, int64_t high) {
+  return value < low ? low : (value > high ? high : value);
+}
+
 static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
   switch (bd) {
     case 8: