]> granicus.if.org Git - libvpx/commitdiff
Make target_frame_bits error margin configurable.
authorangiebird <angiebird@google.com>
Sat, 8 Aug 2020 01:39:18 +0000 (18:39 -0700)
committerangiebird <angiebird@google.com>
Mon, 10 Aug 2020 22:00:51 +0000 (15:00 -0700)
Change-Id: I05dd4d60741743c13951727ce6608acf4224ebec

test/simple_encode_test.cc
vp9/encoder/vp9_encoder.c
vp9/encoder/vp9_encoder.h
vp9/simple_encode.cc
vp9/simple_encode.h

index c5674466d7088d75ea5f9a2cc9aa54c593f98f3c..eeb65c2d285914ea99136f342da0de4de3e230d2 100644 (file)
@@ -182,9 +182,13 @@ TEST_F(SimpleEncodeTest, EncodeFrameWithTargetFrameBits) {
       target_frame_bits = 2000;
     }
 
+    double percent_diff = 15;
+    if (encode_frame_info.frame_type == kFrameTypeOverlay) {
+      percent_diff = 100;
+    }
     EncodeFrameResult encode_frame_result;
-    simple_encode.EncodeFrameWithTargetFrameBits(&encode_frame_result,
-                                                 target_frame_bits);
+    simple_encode.EncodeFrameWithTargetFrameBits(
+        &encode_frame_result, target_frame_bits, percent_diff);
     const int recode_count = encode_frame_result.recode_count;
     // TODO(angiebird): Replace 7 by RATE_CTRL_MAX_RECODE_NUM
     EXPECT_LE(recode_count, 7);
@@ -192,7 +196,7 @@ TEST_F(SimpleEncodeTest, EncodeFrameWithTargetFrameBits) {
 
     double diff = fabs((double)encode_frame_result.coding_data_bit_size -
                        target_frame_bits);
-    EXPECT_LE(diff * 100 / target_frame_bits, 15);
+    EXPECT_LE(diff * 100 / target_frame_bits, percent_diff);
   }
   simple_encode.EndEncode();
 }
index 3348cf66ff64eaf0acd3c2ddc5b7bffbbc6a9299..0485590615109e2a3b85b52287863e69651404a8 100644 (file)
@@ -4526,7 +4526,7 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest
       rq_model_update(rq_history, rc->this_frame_target, rq_model);
 
       // Check if we hit the target bitrate.
-      if (percent_diff <= 15 ||
+      if (percent_diff <= cpi->encode_command.target_frame_bits_error_percent ||
           rq_history->recode_count >= RATE_CTRL_MAX_RECODE_NUM ||
           rq_history->q_index_low >= rq_history->q_index_high) {
         break;
index 0d537ca972c8a2562efb07cad9ede80762d9ab8b..26d35cccf9848d267485c30703f64562c3eb34b6 100644 (file)
@@ -598,8 +598,11 @@ typedef struct RATE_QSTEP_MODEL {
 typedef struct ENCODE_COMMAND {
   int use_external_quantize_index;
   int external_quantize_index;
+
   int use_external_target_frame_bits;
   int target_frame_bits;
+  double target_frame_bits_error_percent;
+
   GOP_COMMAND gop_command;
 } ENCODE_COMMAND;
 
@@ -621,15 +624,19 @@ static INLINE void encode_command_reset_external_quantize_index(
 }
 
 static INLINE void encode_command_set_target_frame_bits(
-    ENCODE_COMMAND *encode_command, int target_frame_bits) {
+    ENCODE_COMMAND *encode_command, int target_frame_bits,
+    double target_frame_bits_error_percent) {
   encode_command->use_external_target_frame_bits = 1;
   encode_command->target_frame_bits = target_frame_bits;
+  encode_command->target_frame_bits_error_percent =
+      target_frame_bits_error_percent;
 }
 
 static INLINE void encode_command_reset_target_frame_bits(
     ENCODE_COMMAND *encode_command) {
   encode_command->use_external_target_frame_bits = 0;
   encode_command->target_frame_bits = -1;
+  encode_command->target_frame_bits_error_percent = 0;
 }
 
 static INLINE void encode_command_init(ENCODE_COMMAND *encode_command) {
index da9c4e10aaec18349a38ca1448e24fc522476a4f..bb7f544792ea6011dfe2b14a90cc895d21a4ea06 100644 (file)
@@ -1098,9 +1098,10 @@ void SimpleEncode::EncodeFrameWithQuantizeIndex(
 }
 
 void SimpleEncode::EncodeFrameWithTargetFrameBits(
-    EncodeFrameResult *encode_frame_result, int target_frame_bits) {
+    EncodeFrameResult *encode_frame_result, int target_frame_bits,
+    double percent_diff) {
   encode_command_set_target_frame_bits(&impl_ptr_->cpi->encode_command,
-                                       target_frame_bits);
+                                       target_frame_bits, percent_diff);
   EncodeFrame(encode_frame_result);
   encode_command_reset_target_frame_bits(&impl_ptr_->cpi->encode_command);
 }
index 702895e05cb95f4cbfa9f624deff63db67a7dc1a..5db85fd7d3960c654648755140d8441e68b61574 100644 (file)
@@ -398,9 +398,14 @@ class SimpleEncode {
 
   // Encode a frame with target frame bits usage.
   // The encoder will find a quantize index to make the actual frame bits usage
-  // match the target.
+  // match the target. EncodeFrameWithTargetFrameBits() will recode the frame
+  // update to 7 times to find a q_index to make the actual_frame_bits to
+  // satisfy following inequality.
+  // |actual_frame_bits - target_frame_bits| * 100 / target_frame_bits
+  // <= percent_diff.
   void EncodeFrameWithTargetFrameBits(EncodeFrameResult *encode_frame_result,
-                                      int target_frame_bits);
+                                      int target_frame_bits,
+                                      double percent_diff);
 
   // Gets the number of coding frames for the video. The coding frames include
   // show frame and no show frame.