summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vp9/simple_encode.cc13
-rw-r--r--vp9/simple_encode.h10
-rw-r--r--vp9/vp9_cx_iface.c7
-rw-r--r--vp9/vp9_cx_iface.h2
4 files changed, 25 insertions, 7 deletions
diff --git a/vp9/simple_encode.cc b/vp9/simple_encode.cc
index 7bce91f7f..1d7214ce5 100644
--- a/vp9/simple_encode.cc
+++ b/vp9/simple_encode.cc
@@ -706,6 +706,7 @@ SimpleEncode::SimpleEncode(int frame_width, int frame_height,
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 @@ SimpleEncode::SimpleEncode(int frame_width, int frame_height,
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 @@ void SimpleEncode::StartEncode() {
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 @@ int SimpleEncode::GetCodingFrameNum() const {
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 @@ std::vector<int> SimpleEncode::ComputeKeyFrameMap() const {
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,
diff --git a/vp9/simple_encode.h b/vp9/simple_encode.h
index b21732070..77197e7a2 100644
--- a/vp9/simple_encode.h
+++ b/vp9/simple_encode.h
@@ -304,6 +304,15 @@ class SimpleEncode {
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 @@ class SimpleEncode {
int frame_rate_den_;
int target_bitrate_;
int num_frames_;
+ int encode_speed_;
std::FILE *in_file_;
std::FILE *out_file_;
diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c
index 9074e1b4e..6caa4f739 100644
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -1899,7 +1899,7 @@ static vp9_extracfg get_extra_cfg() {
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 @@ VP9EncoderConfig vp9_get_encoder_config(int frame_width, int frame_height,
* HEIGHT: frame_height
* FPS: frame_rate
* BITRATE: target_bitrate
+ * CPU_USED:encode_speed
*
* INPUT, OUTPUT, LIMIT will not affect VP9EncoderConfig
*
@@ -1921,9 +1922,10 @@ VP9EncoderConfig vp9_get_encoder_config(int frame_width, int frame_height,
* 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 @@ VP9EncoderConfig vp9_get_encoder_config(int frame_width, int frame_height,
oxcf.tile_columns = 0;
oxcf.frame_parallel_decoding_mode = 0;
oxcf.two_pass_vbrmax_section = 150;
+ oxcf.speed = abs(encode_speed);
return oxcf;
}
diff --git a/vp9/vp9_cx_iface.h b/vp9/vp9_cx_iface.h
index 08569fcc9..3188575dd 100644
--- a/vp9/vp9_cx_iface.h
+++ b/vp9/vp9_cx_iface.h
@@ -19,7 +19,7 @@ extern "C" {
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);