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

Method encode_to_message

libs/scrap/src/common/hwcodec.rs:108–136  ·  view source on GitHub ↗
(&mut self, input: EncodeInput, _ms: i64)

Source from the content-addressed store, hash-verified

106 }
107
108 fn encode_to_message(&mut self, input: EncodeInput, _ms: i64) -> ResultType<VideoFrame> {
109 let mut vf = VideoFrame::new();
110 let mut frames = Vec::new();
111 for frame in self
112 .encode(input.yuv()?)
113 .with_context(|| "Failed to encode")?
114 {
115 frames.push(EncodedVideoFrame {
116 data: Bytes::from(frame.data),
117 pts: frame.pts as _,
118 key: frame.key == 1,
119 ..Default::default()
120 });
121 }
122 if frames.len() > 0 {
123 let frames = EncodedVideoFrames {
124 frames: frames.into(),
125 ..Default::default()
126 };
127 match self.format {
128 DataFormat::H264 => vf.set_h264s(frames),
129 DataFormat::H265 => vf.set_h265s(frames),
130 _ => bail!("unsupported format: {:?}", self.format),
131 }
132 Ok(vf)
133 } else {
134 Err(anyhow!("no valid frame"))
135 }
136 }
137
138 fn yuvfmt(&self) -> crate::EncodeYuvFormat {
139 let pixfmt = if self.pixfmt == AVPixelFormat::AV_PIX_FMT_NV12 {

Callers

nothing calls this directly

Calls 2

yuvMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected