forge
Explore
Log in

Don't you dare go Hollow

ec-hw: hw_speed example (encode_rgb 1080p source, per-codec ms/frame)

Browse files at this commit

a26af31ce70b438041785dc54ff0ba57901a26e0Ahmet Kaan GümüşParent: 5244564
crates/ec-hw/examples/hw_speed.rsadded+26 -0
@@ -0,0 +1,26 @@
1+use ec_hw::{EncCodec, EncoderConfig, FrameMetadata, HwEncoder, RateControlMode, RgbFrame, RgbOrder};
2+use std::time::Instant;
3+
4+fn main() {
5+ let (w, h) = (1920u32, 1080u32);
6+ let frames: Vec<Vec<u8>> = (0..8)
7+ .map(|t| (0..w * h).flat_map(|i| [(i % w + t * 9) as u8, (i / w) as u8, t as u8 * 20, 255]).collect())
8+ .collect();
9+ for codec in [EncCodec::H264, EncCodec::H265, EncCodec::Av1] {
10+ for (ow, oh) in [(1920, 1080), (640, 360)] {
11+ let mut cfg = EncoderConfig::new(codec, ow, oh);
12+ cfg.bitrate = 8_000_000;
13+ cfg.framerate = (60, 1);
14+ cfg.rate_control = RateControlMode::ConstantBitrate;
15+ let Ok(mut enc) = HwEncoder::open(cfg, None) else { continue };
16+ let n = 120;
17+ let start = Instant::now();
18+ for i in 0..n {
19+ let frame = RgbFrame { data: &frames[i % 8], width: w, height: h, stride: w * 4, order: RgbOrder::Bgra };
20+ enc.encode_rgb(&frame, FrameMetadata { timestamp: i as i64, force_keyframe: false }).unwrap();
21+ }
22+ let ms = start.elapsed().as_secs_f64() * 1000.0 / n as f64;
23+ println!("{codec:?} {:?} 1080p->{ow}x{oh}: {ms:.2} ms/frame ({:.0} fps)", enc.backend(), 1000.0 / ms);
24+ }
25+ }
26+}