ref: 16935397ee6712c407f0554e80160054d5eb7188
parent: 8c7142d7737c655d96af156b7dbbf01f3331cc84
author: angiebird <angiebird@google.com>
date: Mon Jun 15 11:09:01 EDT 2020
Add SetEncodeSpeed() to SimpleEncode Change-Id: I2fcf37045a96bb101de3359e2e69dcc266c1dc10
--- a/vp9/simple_encode.cc
+++ b/vp9/simple_encode.cc
@@ -706,6 +706,7 @@
frame_rate_den_ = frame_rate_den;
target_bitrate_ = target_bitrate;
num_frames_ = num_frames;
+ encode_speed_ = 0;
frame_coding_index_ = 0;
show_frame_count_ = 0;
@@ -727,12 +728,16 @@
InitRefFrameInfo(&ref_frame_info_);
}
+void SimpleEncode::SetEncodeSpeed(int encode_speed) {
+ encode_speed_ = encode_speed;
+}
+
void SimpleEncode::ComputeFirstPassStats() {
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_FIRST_PASS);
+ target_bitrate_, encode_speed_, VPX_RC_FIRST_PASS);
VP9_COMP *cpi = init_encoder(&oxcf, impl_ptr_->img_fmt);
struct lookahead_ctx *lookahead = cpi->lookahead;
int i;
@@ -881,7 +886,7 @@
make_vpx_rational(frame_rate_num_, frame_rate_den_);
VP9EncoderConfig oxcf =
vp9_get_encoder_config(frame_width_, frame_height_, frame_rate,
- target_bitrate_, VPX_RC_LAST_PASS);
+ target_bitrate_, encode_speed_, VPX_RC_LAST_PASS);
vpx_fixed_buf_t stats;
stats.buf = GetVectorData(impl_ptr_->first_pass_stats);
stats.sz = sizeof(impl_ptr_->first_pass_stats[0]) *
@@ -1091,7 +1096,7 @@
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);
+ target_bitrate_, encode_speed_, 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,
@@ -1108,7 +1113,7 @@
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);
+ target_bitrate_, encode_speed_, 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,
--- a/vp9/simple_encode.h
+++ b/vp9/simple_encode.h
@@ -304,6 +304,15 @@
SimpleEncode(SimpleEncode &) = delete;
SimpleEncode &operator=(const SimpleEncode &) = delete;
+ // Adjusts the encoder's coding speed.
+ // If this function is not called, the encoder will use default encode_speed
+ // 0. Call this function before ComputeFirstPassStats() if needed.
+ // The encode_speed is equivalent to --cpu-used of the vpxenc command.
+ // The encode_speed's range should be [0, 9].
+ // Setting the encode_speed to a higher level will yield faster coding
+ // at the cost of lower compression efficiency.
+ void SetEncodeSpeed(int encode_speed);
+
// Makes encoder compute the first pass stats and store it at
// impl_ptr_->first_pass_stats. key_frame_map_ is also computed based on the
// first pass stats.
@@ -405,6 +414,7 @@
int frame_rate_den_;
int target_bitrate_;
int num_frames_;
+ int encode_speed_;
std::FILE *in_file_;
std::FILE *out_file_;
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -1899,7 +1899,7 @@
VP9EncoderConfig vp9_get_encoder_config(int frame_width, int frame_height,
vpx_rational_t frame_rate,
- int target_bitrate,
+ int target_bitrate, int encode_speed,
vpx_enc_pass enc_pass) {
/* This function will generate the same VP9EncoderConfig used by the
* vpxenc command given below.
@@ -1910,6 +1910,7 @@
* HEIGHT: frame_height
* FPS: frame_rate
* BITRATE: target_bitrate
+ * CPU_USED:encode_speed
*
* INPUT, OUTPUT, LIMIT will not affect VP9EncoderConfig
*
@@ -1921,9 +1922,10 @@
* BITRATE=600
* FPS=30/1
* LIMIT=150
+ * CPU_USED=0
* ./vpxenc --limit=$LIMIT --width=$WIDTH --height=$HEIGHT --fps=$FPS
* --lag-in-frames=25 \
- * --codec=vp9 --good --cpu-used=0 --threads=0 --profile=0 \
+ * --codec=vp9 --good --cpu-used=CPU_USED --threads=0 --profile=0 \
* --min-q=0 --max-q=63 --auto-alt-ref=1 --passes=2 --kf-max-dist=150 \
* --kf-min-dist=0 --drop-frame=0 --static-thresh=0 --bias-pct=50 \
* --minsection-pct=0 --maxsection-pct=150 --arnr-maxframes=7 --psnr \
@@ -1946,6 +1948,7 @@
oxcf.tile_columns = 0;
oxcf.frame_parallel_decoding_mode = 0;
oxcf.two_pass_vbrmax_section = 150;
+ oxcf.speed = abs(encode_speed);
return oxcf;
}
--- a/vp9/vp9_cx_iface.h
+++ b/vp9/vp9_cx_iface.h
@@ -19,7 +19,7 @@
VP9EncoderConfig vp9_get_encoder_config(int frame_width, int frame_height,
vpx_rational_t frame_rate,
- int target_bitrate,
+ int target_bitrate, int encode_speed,
vpx_enc_pass enc_pass);
void vp9_dump_encoder_config(const VP9EncoderConfig *oxcf);