Skip to content

Commit 71e7422

Browse files
committed
[*] improve openh264 encoder efficiency
1 parent 6f8eb02 commit 71e7422

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

lib/recorder/src/video_encoder/ve_openh264.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ impl OpenH264VideoEncoder {
2323
assert!(config.width > 0 && config.height > 0);
2424

2525
let encoder_config = EncoderConfig::new()
26-
.num_threads(4)
2726
.skip_frames(false)
2827
.profile(Profile::Baseline)
29-
.complexity(Complexity::Low)
28+
.complexity(Complexity::High)
3029
.background_detection(false)
3130
.adaptive_quantization(false)
32-
.rate_control_mode(RateControlMode::Off)
31+
.rate_control_mode(RateControlMode::Bufferbased)
3332
.usage_type(UsageType::ScreenContentRealTime)
3433
.max_frame_rate(FrameRate::from_hz(config.fps.to_u32() as f32));
3534

@@ -189,25 +188,22 @@ impl VideoEncoder for OpenH264VideoEncoder {
189188
)));
190189
}
191190

192-
let now = Instant::now();
193191
let yuv_raw = rgb_to_i420_yuv(&img.as_raw(), self.width, self.height)?;
194192
let yuv_buffer = YUVBuffer::from_vec(yuv_raw, self.width as usize, self.height as usize);
195-
println!("=============== rgb -> yuv: {:.2?}", now.elapsed());
196193

194+
// FIXME: low efficiency(~50ms)
197195
let now = Instant::now();
198196
let bitstream = self.encoder.encode(&yuv_buffer).map_err(|e| {
199197
RecorderError::VideoEncodingFailed(format!("OpenH264 encoding failed: {:?}", e))
200198
})?;
201-
println!("=============== encode: {:.2?}", now.elapsed());
199+
log::debug!("openh264 encode yuv frame spent: {:.2?}", now.elapsed());
202200

203-
let now = Instant::now();
204201
let bitstream_data = bitstream.to_vec();
205202
let final_data = if self.annexb {
206203
bitstream_data
207204
} else {
208205
self.convert_annex_b_to_length_prefixed(&bitstream_data)
209206
};
210-
println!("=== convert_to_length_prefixed: {:.2?}", now.elapsed());
211207

212208
// If this is the first frame and we haven't cached headers yet, try to extract SPS/PPS
213209
if !self.annexb && !self.first_frame_encoded && self.headers_cache.is_none() {

0 commit comments

Comments
 (0)