@@ -3,7 +3,10 @@ use crate::{RecorderError, VideoEncoder, VideoEncoderConfig, recorder::ResizedIm
33use image:: { ImageBuffer , Rgb } ;
44use openh264:: {
55 OpenH264API ,
6- encoder:: { Complexity , Encoder , EncoderConfig , FrameRate , Profile , RateControlMode , UsageType } ,
6+ encoder:: {
7+ Complexity , Encoder , EncoderConfig , FrameRate , IntraFramePeriod , Profile , RateControlMode ,
8+ UsageType ,
9+ } ,
710 formats:: { RgbSliceU8 , YUVBuffer } ,
811} ;
912use std:: time:: Instant ;
@@ -26,9 +29,12 @@ impl OpenH264VideoEncoder {
2629 . skip_frames ( false )
2730 . profile ( Profile :: Baseline )
2831 . complexity ( Complexity :: Low )
29- . rate_control_mode ( RateControlMode :: Quality )
30- . usage_type ( UsageType :: CameraVideoRealTime )
31- . max_frame_rate ( FrameRate :: from_hz ( config. fps . to_u32 ( ) as f32 ) ) ;
32+ . background_detection ( false )
33+ . adaptive_quantization ( false )
34+ . rate_control_mode ( RateControlMode :: Timestamp )
35+ . usage_type ( UsageType :: ScreenContentRealTime )
36+ . max_frame_rate ( FrameRate :: from_hz ( config. fps . to_u32 ( ) as f32 ) )
37+ . intra_frame_period ( IntraFramePeriod :: from_num_frames ( config. fps . to_u32 ( ) ) ) ;
3238
3339 let encoder = Encoder :: with_api_config ( OpenH264API :: from_source ( ) , encoder_config)
3440 . map_err ( |e| {
@@ -189,7 +195,6 @@ impl VideoEncoder for OpenH264VideoEncoder {
189195 let yuv_raw = rgb_to_i420_yuv ( & img. as_raw ( ) , self . width , self . height ) ?;
190196 let yuv_buffer = YUVBuffer :: from_vec ( yuv_raw, self . width as usize , self . height as usize ) ;
191197
192- // FIXME: low efficiency(~50ms)
193198 let now = Instant :: now ( ) ;
194199 let bitstream = self . encoder . encode ( & yuv_buffer) . map_err ( |e| {
195200 RecorderError :: VideoEncodingFailed ( format ! ( "OpenH264 encoding failed: {:?}" , e) )
0 commit comments