diff --git a/crates/ec-h264/examples/bench_encode.rs b/crates/ec-h264/examples/bench_encode.rs deleted file mode 100644 index e1ec1b26..00000000 --- a/crates/ec-h264/examples/bench_encode.rs +++ /dev/null @@ -1,36 +0,0 @@ -//! Throwaway profiling harness for lane-h264perf: repeats the bench's own -//! 640x360x30-frame encode loop N times so a perf sample has enough hits to -//! be useful. Not wired into any product surface; delete before merge if -//! still present. -use ec_h264::{Encoder, EncoderConfig, PictureView}; -use std::time::Instant; - -fn main() { - let path = std::env::args().nth(1).expect("path to raw yuv420p"); - let reps: u32 = std::env::args() - .nth(2) - .and_then(|s| s.parse().ok()) - .unwrap_or(20); - let (w, h) = (640u32, 360u32); - let data = std::fs::read(&path).expect("read raw yuv"); - let frame_len = (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize; - let n = data.len() / frame_len; - let start = Instant::now(); - for _ in 0..reps { - let mut cfg = EncoderConfig::new(w, h); - cfg.threads = 1; - let mut enc = Encoder::new(cfg).expect("h264 encoder"); - for frame in data.chunks_exact(frame_len).take(n) { - let (y, rest) = frame.split_at((w * h) as usize); - let (u, v) = rest.split_at(rest.len() / 2); - let view = PictureView::i420(w, h, y, u, v); - enc.encode(&view).expect("h264 encode"); - } - } - let wall = start.elapsed(); - eprintln!( - "{reps} reps x {n} frames in {:.3}s ({:.2} ms/rep)", - wall.as_secs_f64(), - wall.as_secs_f64() * 1000.0 / f64::from(reps) - ); -} diff --git a/crates/ec-h264/examples/h264_clip_encode.rs b/crates/ec-h264/examples/h264_clip_encode.rs deleted file mode 100644 index 8b5ebbb3..00000000 --- a/crates/ec-h264/examples/h264_clip_encode.rs +++ /dev/null @@ -1,107 +0,0 @@ -//! Encode a raw I420 clip and write the bitstream and the encoder's own -//! reconstruction, for the ffmpeg recon-match and rate-control checks in -//! `scripts/h264-lane-check.sh`. Not a product surface. -//! -//! Usage: h264_clip_encode -//! -//! `-` reads raw I420 from stdin, so a 60 s 1080p clip never has to exist on -//! disk. Writes `.h264` (Annex B), and `.recon.yuv` -//! (every reconstructed picture, display order, I420 at the coded size) unless -//! the prefix is `none`. Prints frames, bytes and the wall time spent inside -//! `encode` on stdout. -use ec_h264::{Encoder, EncoderConfig, PictureView}; -use std::io::Write; -use std::time::Instant; - -fn main() { - let args: Vec = std::env::args().collect(); - if args.len() != 9 { - eprintln!( - "usage: h264_clip_encode " - ); - std::process::exit(2); - } - let parse = |i: usize| -> f64 { args[i].parse().expect("numeric argument") }; - let (w, h) = (parse(2) as u32, parse(3) as u32); - let fps = parse(4) as f32; - let bitrate = parse(5) as u32; - let qp = parse(6) as i32; - let threads = parse(7) as usize; - let prefix = &args[8]; - - let (wu, hu) = (w as usize, h as usize); - let cw = wu.div_ceil(2); - let ch = hu.div_ceil(2); - let frame_len = wu * hu + 2 * cw * ch; - let mut input: Box = if args[1] == "-" { - Box::new(std::io::stdin().lock()) - } else { - Box::new(std::fs::File::open(&args[1]).expect("open raw i420 input")) - }; - - let mut cfg = EncoderConfig::new(w, h); - cfg.framerate = fps; - cfg.bitrate = bitrate; - cfg.qp = qp; - cfg.threads = threads; - // H264_CAVLC=1 codes CAVLC instead of the default CABAC (identity checks). - cfg.cabac = std::env::var_os("H264_CAVLC").is_none(); - cfg.gop_size = (fps.round() as u32).max(1) * 2; - let mut enc = Encoder::new(cfg).expect("h264 encoder"); - - let mut stream_out = (prefix != "none") - .then(|| std::fs::File::create(format!("{prefix}.h264")).expect("create bitstream")); - let mut recon_out = (prefix != "none") - .then(|| std::fs::File::create(format!("{prefix}.recon.yuv")).expect("create recon")); - // H264_TRACE=1 prints one line per picture: its QP and size. - let trace = std::env::var_os("H264_TRACE").is_some(); - let mut frame = vec![0u8; frame_len]; - let mut frames = 0usize; - let mut bytes = 0usize; - let mut spent = std::time::Duration::ZERO; - while input.read_exact(&mut frame).is_ok() { - let (y, rest) = frame.split_at(wu * hu); - let (u, v) = rest.split_at(cw * ch); - let view = PictureView::i420(w, h, y, u, v); - let t0 = Instant::now(); - let pic = enc.encode(&view).expect("h264 encode"); - spent += t0.elapsed(); - if trace { - println!( - "trace {frames} key {} qp {} bytes {}", - u8::from(pic.key_frame), - pic.qp, - pic.au.len() - ); - } - frames += 1; - bytes += pic.au.len(); - if let Some(out) = stream_out.as_mut() { - out.write_all(&pic.au).expect("write bitstream"); - } - if let Some(out) = recon_out.as_mut() { - let (ry, ru, rv) = enc.reconstruction().expect("a reconstruction"); - out.write_all(&ry) - .and_then(|_| out.write_all(&ru)) - .and_then(|_| out.write_all(&rv)) - .expect("write reconstruction"); - } - } - println!( - "frames {frames} bytes {bytes} encode_secs {:.3} fps {:.2}", - spent.as_secs_f64(), - frames as f64 / spent.as_secs_f64() - ); - let t = enc.timings(); - println!( - "stages pad {:.3} bands_wall {:.3} bands_busy {:.3} bands_slowest {:.3} stitch {:.3} deblock {:.3} output {:.3}", - t.pad, t.bands_wall, t.bands_busy, t.bands_slowest, t.stitch, t.deblock, t.output - ); - #[cfg(feature = "enc-profile")] - { - let snap = ec_h264::mb_stages::snapshot(); - for (name, ns) in ec_h264::mb_stages::NAMES.iter().zip(snap) { - println!("mb_stage {name} {:.3}", ns as f64 / 1e9); - } - } -}