forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

hw_speed.rs26 lines, 1.3 KiBHistoryRawDownload
1use ec_hw::{EncCodec, EncoderConfig, FrameMetadata, HwEncoder, RateControlMode, RgbFrame, RgbOrder};
2use std::time::Instant;
3
4fn 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}