U6: ec-h264 delete bench_encode and h264_clip_encode examples (encoder timing and perf probes, no test or user)
Browse files at this commit7e20a36e16354f0035326bf091313ec1697fa311Parent: 41510f02 changed files +0 -143
crates/ec-h264/examples/bench_encode.rsdeleted+0 -36
| @@ -1,36 +0,0 @@ | |||
| 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. | ||
| 5 | -use ec_h264::{Encoder, EncoderConfig, PictureView}; | ||
| 6 | -use std::time::Instant; | ||
| 7 | - | ||
| 8 | -fn main() { | ||
| 9 | - let path = std::env::args().nth(1).expect("path to raw yuv420p"); | ||
| 10 | - let reps: u32 = std::env::args() | ||
| 11 | - .nth(2) | ||
| 12 | - .and_then(|s| s.parse().ok()) | ||
| 13 | - .unwrap_or(20); | ||
| 14 | - let (w, h) = (640u32, 360u32); | ||
| 15 | - let data = std::fs::read(&path).expect("read raw yuv"); | ||
| 16 | - let frame_len = (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize; | ||
| 17 | - let n = data.len() / frame_len; | ||
| 18 | - let start = Instant::now(); | ||
| 19 | - for _ in 0..reps { | ||
| 20 | - let mut cfg = EncoderConfig::new(w, h); | ||
| 21 | - cfg.threads = 1; | ||
| 22 | - let mut enc = Encoder::new(cfg).expect("h264 encoder"); | ||
| 23 | - for frame in data.chunks_exact(frame_len).take(n) { | ||
| 24 | - let (y, rest) = frame.split_at((w * h) as usize); | ||
| 25 | - let (u, v) = rest.split_at(rest.len() / 2); | ||
| 26 | - let view = PictureView::i420(w, h, y, u, v); | ||
| 27 | - enc.encode(&view).expect("h264 encode"); | ||
| 28 | - } | ||
| 29 | - } | ||
| 30 | - let wall = start.elapsed(); | ||
| 31 | - eprintln!( | ||
| 32 | - "{reps} reps x {n} frames in {:.3}s ({:.2} ms/rep)", | ||
| 33 | - wall.as_secs_f64(), | ||
| 34 | - wall.as_secs_f64() * 1000.0 / f64::from(reps) | ||
| 35 | - ); | ||
| 36 | -} | ||
crates/ec-h264/examples/h264_clip_encode.rsdeleted+0 -107
| @@ -1,107 +0,0 @@ | |||
| 1 | -//! Encode a raw I420 clip and write the bitstream and the encoder's own | ||
| 2 | -//! reconstruction, for the ffmpeg recon-match and rate-control checks in | ||
| 3 | -//! `scripts/h264-lane-check.sh`. Not a product surface. | ||
| 4 | -//! | ||
| 5 | -//! Usage: h264_clip_encode <in.yuv|-> <width> <height> <fps> <bitrate|0> <qp> <threads> <out-prefix|none> | ||
| 6 | -//! | ||
| 7 | -//! `-` reads raw I420 from stdin, so a 60 s 1080p clip never has to exist on | ||
| 8 | -//! disk. Writes `<out-prefix>.h264` (Annex B), and `<out-prefix>.recon.yuv` | ||
| 9 | -//! (every reconstructed picture, display order, I420 at the coded size) unless | ||
| 10 | -//! the prefix is `none`. Prints frames, bytes and the wall time spent inside | ||
| 11 | -//! `encode` on stdout. | ||
| 12 | -use ec_h264::{Encoder, EncoderConfig, PictureView}; | ||
| 13 | -use std::io::Write; | ||
| 14 | -use std::time::Instant; | ||
| 15 | - | ||
| 16 | -fn main() { | ||
| 17 | - let args: Vec<String> = std::env::args().collect(); | ||
| 18 | - if args.len() != 9 { | ||
| 19 | - eprintln!( | ||
| 20 | - "usage: h264_clip_encode <in.yuv|-> <w> <h> <fps> <bitrate> <qp> <threads> <out-prefix|none>" | ||
| 21 | - ); | ||
| 22 | - std::process::exit(2); | ||
| 23 | - } | ||
| 24 | - let parse = |i: usize| -> f64 { args[i].parse().expect("numeric argument") }; | ||
| 25 | - let (w, h) = (parse(2) as u32, parse(3) as u32); | ||
| 26 | - let fps = parse(4) as f32; | ||
| 27 | - let bitrate = parse(5) as u32; | ||
| 28 | - let qp = parse(6) as i32; | ||
| 29 | - let threads = parse(7) as usize; | ||
| 30 | - let prefix = &args[8]; | ||
| 31 | - | ||
| 32 | - let (wu, hu) = (w as usize, h as usize); | ||
| 33 | - let cw = wu.div_ceil(2); | ||
| 34 | - let ch = hu.div_ceil(2); | ||
| 35 | - let frame_len = wu * hu + 2 * cw * ch; | ||
| 36 | - let mut input: Box<dyn std::io::Read> = if args[1] == "-" { | ||
| 37 | - Box::new(std::io::stdin().lock()) | ||
| 38 | - } else { | ||
| 39 | - Box::new(std::fs::File::open(&args[1]).expect("open raw i420 input")) | ||
| 40 | - }; | ||
| 41 | - | ||
| 42 | - let mut cfg = EncoderConfig::new(w, h); | ||
| 43 | - cfg.framerate = fps; | ||
| 44 | - cfg.bitrate = bitrate; | ||
| 45 | - cfg.qp = qp; | ||
| 46 | - cfg.threads = threads; | ||
| 47 | - // H264_CAVLC=1 codes CAVLC instead of the default CABAC (identity checks). | ||
| 48 | - cfg.cabac = std::env::var_os("H264_CAVLC").is_none(); | ||
| 49 | - cfg.gop_size = (fps.round() as u32).max(1) * 2; | ||
| 50 | - let mut enc = Encoder::new(cfg).expect("h264 encoder"); | ||
| 51 | - | ||
| 52 | - let mut stream_out = (prefix != "none") | ||
| 53 | - .then(|| std::fs::File::create(format!("{prefix}.h264")).expect("create bitstream")); | ||
| 54 | - let mut recon_out = (prefix != "none") | ||
| 55 | - .then(|| std::fs::File::create(format!("{prefix}.recon.yuv")).expect("create recon")); | ||
| 56 | - // H264_TRACE=1 prints one line per picture: its QP and size. | ||
| 57 | - let trace = std::env::var_os("H264_TRACE").is_some(); | ||
| 58 | - let mut frame = vec![0u8; frame_len]; | ||
| 59 | - let mut frames = 0usize; | ||
| 60 | - let mut bytes = 0usize; | ||
| 61 | - let mut spent = std::time::Duration::ZERO; | ||
| 62 | - while input.read_exact(&mut frame).is_ok() { | ||
| 63 | - let (y, rest) = frame.split_at(wu * hu); | ||
| 64 | - let (u, v) = rest.split_at(cw * ch); | ||
| 65 | - let view = PictureView::i420(w, h, y, u, v); | ||
| 66 | - let t0 = Instant::now(); | ||
| 67 | - let pic = enc.encode(&view).expect("h264 encode"); | ||
| 68 | - spent += t0.elapsed(); | ||
| 69 | - if trace { | ||
| 70 | - println!( | ||
| 71 | - "trace {frames} key {} qp {} bytes {}", | ||
| 72 | - u8::from(pic.key_frame), | ||
| 73 | - pic.qp, | ||
| 74 | - pic.au.len() | ||
| 75 | - ); | ||
| 76 | - } | ||
| 77 | - frames += 1; | ||
| 78 | - bytes += pic.au.len(); | ||
| 79 | - if let Some(out) = stream_out.as_mut() { | ||
| 80 | - out.write_all(&pic.au).expect("write bitstream"); | ||
| 81 | - } | ||
| 82 | - if let Some(out) = recon_out.as_mut() { | ||
| 83 | - let (ry, ru, rv) = enc.reconstruction().expect("a reconstruction"); | ||
| 84 | - out.write_all(&ry) | ||
| 85 | - .and_then(|_| out.write_all(&ru)) | ||
| 86 | - .and_then(|_| out.write_all(&rv)) | ||
| 87 | - .expect("write reconstruction"); | ||
| 88 | - } | ||
| 89 | - } | ||
| 90 | - println!( | ||
| 91 | - "frames {frames} bytes {bytes} encode_secs {:.3} fps {:.2}", | ||
| 92 | - spent.as_secs_f64(), | ||
| 93 | - frames as f64 / spent.as_secs_f64() | ||
| 94 | - ); | ||
| 95 | - let t = enc.timings(); | ||
| 96 | - println!( | ||
| 97 | - "stages pad {:.3} bands_wall {:.3} bands_busy {:.3} bands_slowest {:.3} stitch {:.3} deblock {:.3} output {:.3}", | ||
| 98 | - t.pad, t.bands_wall, t.bands_busy, t.bands_slowest, t.stitch, t.deblock, t.output | ||
| 99 | - ); | ||
| 100 | - #[cfg(feature = "enc-profile")] | ||
| 101 | - { | ||
| 102 | - let snap = ec_h264::mb_stages::snapshot(); | ||
| 103 | - for (name, ns) in ec_h264::mb_stages::NAMES.iter().zip(snap) { | ||
| 104 | - println!("mb_stage {name} {:.3}", ns as f64 / 1e9); | ||
| 105 | - } | ||
| 106 | - } | ||
| 107 | -} | ||