shithub: libvpx

Download patch

ref: a53b7e53e8eaf121c16a7f93117f85f38e5bd591
parent: 204ba94f4b0403a0289a5600fda56e64f89ce67c
author: angiebird <angiebird@google.com>
date: Wed Dec 11 10:43:48 EST 2019

Add GetFramePixelCount to SimpleEncode

Gets the total number of pixels of YUV planes per frame.

Change-Id: Ifdf35190cdde1378de6d7e93ab4428868a5795fa

--- a/test/simple_encode_test.cc
+++ b/test/simple_encode_test.cc
@@ -168,5 +168,12 @@
   simple_encode.EndEncode();
 }
 
+TEST(SimpleEncode, GetFramePixelCount) {
+  SimpleEncode simple_encode(w, h, frame_rate_num, frame_rate_den,
+                             target_bitrate, num_frames, infile_path);
+  EXPECT_EQ(simple_encode.GetFramePixelCount(),
+            static_cast<uint64_t>(w * h * 3 / 2));
+}
+
 }  // namespace
 }  // namespace vp9
--- a/vp9/simple_encode.cc
+++ b/vp9/simple_encode.cc
@@ -377,6 +377,22 @@
                                   multi_layer_arf, allow_alt_ref);
 }
 
+uint64_t SimpleEncode::GetFramePixelCount() const {
+  assert(frame_width_ % 2 == 0);
+  assert(frame_heigh_ % 2 == 0);
+  switch (impl_ptr_->img_fmt) {
+    case VPX_IMG_FMT_I420: return frame_width_ * frame_height_ * 3 / 2;
+    case VPX_IMG_FMT_I422: return frame_width_ * frame_height_ * 2;
+    case VPX_IMG_FMT_I444: return frame_width_ * frame_height_ * 3;
+    case VPX_IMG_FMT_I440: return frame_width_ * frame_height_ * 2;
+    case VPX_IMG_FMT_I42016: return frame_width_ * frame_height_ * 3 / 2;
+    case VPX_IMG_FMT_I42216: return frame_width_ * frame_height_ * 2;
+    case VPX_IMG_FMT_I44416: return frame_width_ * frame_height_ * 3;
+    case VPX_IMG_FMT_I44016: return frame_width_ * frame_height_ * 2;
+    default: return 0;
+  }
+}
+
 SimpleEncode::~SimpleEncode() {
   if (this->file_ != NULL) {
     fclose(this->file_);
--- a/vp9/simple_encode.h
+++ b/vp9/simple_encode.h
@@ -104,6 +104,9 @@
   // This function should be called after ComputeFirstPassStats().
   int GetCodingFrameNum() const;
 
+  // Gets the total number of pixels of YUV planes per frame.
+  uint64_t GetFramePixelCount() const;
+
  private:
   class EncodeImpl;