forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBbede77eTahinli2 months ago3534 commits

bench_encode.rs33 lines, 1.4 KiBHistoryRawDownload
1//! Throwaway profiling harness for lane-h264perf: repeats the bench's own
2//! 640x360x30-frame encode loop N times so a perf sample has enough hits to
3//! be useful. Not wired into any product surface; delete before merge if
4//! still present.
5use ec_h264::{Encoder, EncoderConfig, PictureView};
6use std::time::Instant;
7
8fn main() {
9 let path = std::env::args().nth(1).expect("path to raw yuv420p");
10 let reps: u32 = std::env::args().nth(2).and_then(|s| s.parse().ok()).unwrap_or(20);
11 let (w, h) = (640u32, 360u32);
12 let data = std::fs::read(&path).expect("read raw yuv");
13 let frame_len = (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize;
14 let n = data.len() / frame_len;
15 let start = Instant::now();
16 for _ in 0..reps {
17 let mut cfg = EncoderConfig::new(w, h);
18 cfg.threads = 1;
19 let mut enc = Encoder::new(cfg).expect("h264 encoder");
20 for frame in data.chunks_exact(frame_len).take(n) {
21 let (y, rest) = frame.split_at((w * h) as usize);
22 let (u, v) = rest.split_at(rest.len() / 2);
23 let view = PictureView::i420(w, h, y, u, v);
24 enc.encode(&view).expect("h264 encode");
25 }
26 }
27 let wall = start.elapsed();
28 eprintln!(
29 "{reps} reps x {n} frames in {:.3}s ({:.2} ms/rep)",
30 wall.as_secs_f64(),
31 wall.as_secs_f64() * 1000.0 / f64::from(reps)
32 );
33}