]> granicus.if.org Git - libvpx/commitdiff
Add SimpleEncode::GetCodingFrameNum()
authorangiebird <angiebird@google.com>
Mon, 11 Nov 2019 04:36:04 +0000 (20:36 -0800)
committerangiebird <angiebird@google.com>
Mon, 18 Nov 2019 19:37:24 +0000 (11:37 -0800)
Also add unit tests for GetCodingFrameNum() and EncodeFrame()

Change-Id: I3e7b65f47226be4660409481435f8f784db72a68

test/simple_encode_test.cc
vp9/simple_encode.cc
vp9/simple_encode.h

index 48f68a9a44673353a32c23fc3b0a3e4216faf793..b917e028e7dd305a40d62f686e3aff619adff4bc 100644 (file)
@@ -33,4 +33,45 @@ TEST(SimpleEncode, ComputeFirstPassStats) {
   }
 }
 
+TEST(SimpleEncode, GetCodingFrameNum) {
+  int w = 352;
+  int h = 288;
+  int frame_rate_num = 30;
+  int frame_rate_den = 1;
+  int target_bitrate = 200;
+  int num_frames = 17;
+  // TODO(angiebird): Figure out how to upload test video to our codebase
+  FILE *file = fopen("bus_352x288_420_f20_b8.yuv", "r");
+  SimpleEncode simple_encode(w, h, frame_rate_num, frame_rate_den,
+                             target_bitrate, num_frames, file);
+  simple_encode.ComputeFirstPassStats();
+  int num_coding_frames = simple_encode.GetCodingFrameNum();
+  EXPECT_EQ(num_coding_frames, 19);
+}
+
+TEST(SimpleEncode, EncodeFrame) {
+  int w = 352;
+  int h = 288;
+  int frame_rate_num = 30;
+  int frame_rate_den = 1;
+  int target_bitrate = 200;
+  int num_frames = 17;
+  // TODO(angiebird): Figure out how to upload test video to our codebase
+  FILE *file = fopen("bus_352x288_420_f20_b8.yuv", "r");
+  SimpleEncode simple_encode(w, h, frame_rate_num, frame_rate_den,
+                             target_bitrate, num_frames, file);
+  char cx_data[352 * 288 * 3];
+  size_t max_size = 352 * 288 * 3;
+  size_t frame_size;
+  simple_encode.ComputeFirstPassStats();
+  int num_coding_frames = simple_encode.GetCodingFrameNum();
+  simple_encode.StartEncode();
+  for (int i = 0; i < num_coding_frames; ++i) {
+    simple_encode.EncodeFrame(cx_data, &frame_size, max_size);
+    // TODO(angiebird): For now, this test just check whether EncodeFrame can be
+    // run proprly. Add extra check later.
+  }
+  simple_encode.EndEncode();
+}
+
 }  // namespace
index a3adc0a6727a9fc50bbf6974bf0ef82187c44815..8f6fac0d7ed85abe95faea0e0bc0871a063853ac 100644 (file)
@@ -223,4 +223,20 @@ void SimpleEncode::EncodeFrame(char *cx_data, size_t *size, size_t max_size) {
   }
 }
 
+int SimpleEncode::GetCodingFrameNum() {
+  assert(pimpl->frame_stats.size() - 1 > 0);
+  // These are the default settings for now.
+  const int multi_layer_arf = 0;
+  const int allow_alt_ref = 1;
+  vpx_rational_t frame_rate = make_vpx_rational(frame_rate_num, frame_rate_den);
+  const VP9EncoderConfig oxcf = vp9_get_encoder_config(
+      frame_width, frame_height, frame_rate, target_bitrate, VPX_RC_LAST_PASS);
+  FRAME_INFO frame_info = vp9_get_frame_info(&oxcf);
+  FIRST_PASS_INFO first_pass_info;
+  fps_init_first_pass_info(&first_pass_info, pimpl->frame_stats.data(),
+                           num_frames);
+  return vp9_get_coding_frame_num(&oxcf, &frame_info, &first_pass_info,
+                                  multi_layer_arf, allow_alt_ref);
+}
+
 SimpleEncode::~SimpleEncode() {}
index 6308ff5eaff4a48398c723b59d4d4313129e8bb8..bc8b70babf7f95b14c806aed2ef48a3759b93422 100644 (file)
@@ -17,14 +17,22 @@ class SimpleEncode {
   std::vector<std::vector<double>> ObserveFirstPassStats();
 
   // Initialize the encoder for actual encoding
+  // This funtion should be called after ComputeFirstPassStats()
   void StartEncode();
 
   // Free the encoder
+  // This funtion should be called after StartEncode() or EncodeFrame()
   void EndEncode();
 
   // Encode a frame
+  // This funtion should be called after StartEncode() before EndEncode()
   void EncodeFrame(char *cx_data, size_t *size, size_t max_size);
 
+  // Get the number of coding frames for the video. The coding frames include
+  // show frame and no show frame.
+  // This funtion should be called after ComputeFirstPassStats()
+  int GetCodingFrameNum();
+
  private:
   class impl;
   int frame_width;