MCPcopy Create free account
hub / github.com/Recordscript/recordscript / new

Method new

libs/scrap/src/common/hwcodec.rs:56–106  ·  view source on GitHub ↗
(cfg: EncoderCfg, _i444: bool)

Source from the content-addressed store, hash-verified

54
55impl EncoderApi for HwRamEncoder {
56 fn new(cfg: EncoderCfg, _i444: bool) -> ResultType<Self>
57 where
58 Self: Sized,
59 {
60 match cfg {
61 EncoderCfg::HWRAM(config) => {
62 let b = Self::convert_quality(&config.name, config.quality);
63 let base_bitrate = base_bitrate(config.width as _, config.height as _);
64 let mut bitrate = base_bitrate * b / 100;
65 if base_bitrate <= 0 {
66 bitrate = base_bitrate;
67 }
68 bitrate = Self::check_bitrate_range(&config, bitrate);
69 let gop = config.keyframe_interval.unwrap_or(DEFAULT_GOP as _) as i32;
70 let ctx = EncodeContext {
71 name: config.name.clone(),
72 mc_name: config.mc_name.clone(),
73 width: config.width as _,
74 height: config.height as _,
75 pixfmt: DEFAULT_PIXFMT,
76 align: HW_STRIDE_ALIGN as _,
77 kbs: bitrate as i32,
78 timebase: DEFAULT_TIME_BASE,
79 gop,
80 quality: DEFAULT_HW_QUALITY,
81 rc: DEFAULT_RC,
82 thread_count: codec_thread_num(16) as _, // ffmpeg's thread_count is used for cpu
83 };
84 let format = match Encoder::format_from_name(config.name.clone()) {
85 Ok(format) => format,
86 Err(_) => {
87 return Err(anyhow!(format!(
88 "failed to get format from name:{}",
89 config.name
90 )))
91 }
92 };
93 match Encoder::new(ctx.clone()) {
94 Ok(encoder) => Ok(HwRamEncoder {
95 encoder,
96 format,
97 pixfmt: ctx.pixfmt,
98 bitrate,
99 config,
100 }),
101 Err(_) => Err(anyhow!(format!("Failed to create encoder"))),
102 }
103 }
104 _ => Err(anyhow!("encoder type mismatch")),
105 }
106 }
107
108 fn encode_to_message(&mut self, input: EncodeInput, _ms: i64) -> ResultType<VideoFrame> {
109 let mut vf = VideoFrame::new();

Callers

nothing calls this directly

Calls 4

base_bitrateFunction · 0.85
codec_thread_numFunction · 0.85
clear_codec_infoFunction · 0.85
cloneMethod · 0.45

Tested by

no test coverage detected