U19: ec-bench: Row::timed for the timed rows, one extract_raw for 8 and 10-bit, one AV1 HW bench parameterised by depth; ec-va linux-only dependency. Bench output label of the 8-bit HW row now names its pixel format
Browse files at this commit3739e1a1d774704fb74037061a7b5b5f8dcd3561Parent: eafdbd52 changed files +123 -267
- tools/ec-bench/Cargo.toml +3 -1
- tools/ec-bench/src/main.rs +120 -266
tools/ec-bench/Cargo.tomlmodified+3 -1
| @@ -19,7 +19,6 @@ ec-h264 = { workspace = true } | |||
| 19 | ec-h265 = { workspace = true } | 19 | ec-h265 = { workspace = true } |
| 20 | ec-av1 = { workspace = true } | 20 | ec-av1 = { workspace = true } |
| 21 | ec-hw = { workspace = true } | 21 | ec-hw = { workspace = true } |
| 22 | -ec-va = { workspace = true } | ||
| 23 | ec-probe = { workspace = true } | 22 | ec-probe = { workspace = true } |
| 24 | ec-h264-syntax = { workspace = true } | 23 | ec-h264-syntax = { workspace = true } |
| 25 | ec-image = { workspace = true } | 24 | ec-image = { workspace = true } |
| @@ -33,3 +32,6 @@ ec-alac = { workspace = true } | |||
| 33 | ec-ac3 = { workspace = true } | 32 | ec-ac3 = { workspace = true } |
| 34 | ec-truehd = { workspace = true } | 33 | ec-truehd = { workspace = true } |
| 35 | ec-testkit.workspace = true | 34 | ec-testkit.workspace = true |
| 35 | + | ||
| 36 | +[target.'cfg(target_os = "linux")'.dependencies] | ||
| 37 | +ec-va = { workspace = true } | ||
tools/ec-bench/src/main.rsmodified+120 -266
| @@ -37,14 +37,35 @@ struct Row { | |||
| 37 | rtf: Option<f64>, | 37 | rtf: Option<f64>, |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | +impl Row { | ||
| 41 | + fn timed( | ||
| 42 | + component: &'static str, | ||
| 43 | + direction: &'static str, | ||
| 44 | + content: String, | ||
| 45 | + media_s: f64, | ||
| 46 | + wall: f64, | ||
| 47 | + ) -> Row { | ||
| 48 | + Row { | ||
| 49 | + component, | ||
| 50 | + direction, | ||
| 51 | + content, | ||
| 52 | + media: format!("{media_s:.1}s"), | ||
| 53 | + wall_ms: wall * 1000.0, | ||
| 54 | + rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | +} | ||
| 58 | + | ||
| 40 | fn main() -> ec_core::Result<()> { | 59 | fn main() -> ec_core::Result<()> { |
| 41 | let mut rows = Vec::new(); | 60 | let mut rows = Vec::new(); |
| 42 | 61 | ||
| 43 | bench_h264(&mut rows)?; | 62 | bench_h264(&mut rows)?; |
| 44 | bench_h265_encode(&mut rows); | 63 | bench_h265_encode(&mut rows); |
| 45 | bench_av1_encode(&mut rows); | 64 | bench_av1_encode(&mut rows); |
| 46 | - bench_hw_av1_encode(&mut rows); | 65 | + #[cfg(target_os = "linux")] |
| 47 | - bench_hw_av1_encode_10bit(&mut rows); | 66 | + bench_hw_av1_encode(&mut rows, false); |
| 67 | + #[cfg(target_os = "linux")] | ||
| 68 | + bench_hw_av1_encode(&mut rows, true); | ||
| 48 | bench_audio_decode(&mut rows)?; | 69 | bench_audio_decode(&mut rows)?; |
| 49 | bench_audio_encode(&mut rows); | 70 | bench_audio_encode(&mut rows); |
| 50 | bench_truehd(&mut rows); | 71 | bench_truehd(&mut rows); |
| @@ -166,25 +187,20 @@ fn bench_h264(rows: &mut Vec<Row>) -> ec_core::Result<()> { | |||
| 166 | .and_then(|s| parse_ratio(&s)) | 187 | .and_then(|s| parse_ratio(&s)) |
| 167 | .unwrap_or(25.0); | 188 | .unwrap_or(25.0); |
| 168 | let media_s = frames as f64 / fps; | 189 | let media_s = frames as f64 / fps; |
| 169 | - rows.push(Row { | 190 | + rows.push(Row::timed("ec-h264", "decode", format!("{w}x{h} film, {frames} frames"), media_s, wall)); |
| 170 | - component: "ec-h264", | ||
| 171 | - direction: "decode", | ||
| 172 | - content: format!("{w}x{h} film, {frames} frames"), | ||
| 173 | - media: format!("{media_s:.1}s"), | ||
| 174 | - wall_ms: wall * 1000.0, | ||
| 175 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 176 | - }); | ||
| 177 | } else { | 191 | } else { |
| 178 | rows.push(missing("ec-h264", "decode")); | 192 | rows.push(missing("ec-h264", "decode")); |
| 179 | } | 193 | } |
| 180 | 194 | ||
| 181 | // encode: 30 raw yuv420p frames scaled to 640x360 from the same clip. | 195 | // encode: 30 raw yuv420p frames scaled to 640x360 from the same clip. |
| 182 | - let (planes, ew, eh, n) = extract_yuv420p(&src, 640, 360, 30); | 196 | + let (ew, eh) = (640, 360); |
| 197 | + let planes = extract_raw(&src, ew, eh, 30, "yuv420p"); | ||
| 198 | + let frame_len = yuv420_frame_len(ew, eh, 1); | ||
| 199 | + let n = (planes.len() / frame_len) as u32; | ||
| 183 | if n > 0 { | 200 | if n > 0 { |
| 184 | let mut cfg = H264Config::new(ew, eh); | 201 | let mut cfg = H264Config::new(ew, eh); |
| 185 | cfg.threads = 1; // one worker: single-core cost, not a parallelism claim | 202 | cfg.threads = 1; // one worker: single-core cost, not a parallelism claim |
| 186 | let mut enc = H264Encoder::new(cfg).expect("h264 encoder"); | 203 | let mut enc = H264Encoder::new(cfg).expect("h264 encoder"); |
| 187 | - let frame_len = (ew * eh + 2 * (ew.div_ceil(2) * eh.div_ceil(2))) as usize; | ||
| 188 | let start = Instant::now(); | 204 | let start = Instant::now(); |
| 189 | for frame in planes.chunks_exact(frame_len) { | 205 | for frame in planes.chunks_exact(frame_len) { |
| 190 | let (y, rest) = frame.split_at((ew * eh) as usize); | 206 | let (y, rest) = frame.split_at((ew * eh) as usize); |
| @@ -194,23 +210,20 @@ fn bench_h264(rows: &mut Vec<Row>) -> ec_core::Result<()> { | |||
| 194 | } | 210 | } |
| 195 | let wall = start.elapsed().as_secs_f64(); | 211 | let wall = start.elapsed().as_secs_f64(); |
| 196 | let media_s = n as f64 / 30.0; | 212 | let media_s = n as f64 / 30.0; |
| 197 | - rows.push(Row { | 213 | + rows.push(Row::timed("ec-h264", "encode", format!("{ew}x{eh}, {n} frames, 1 thread"), media_s, wall)); |
| 198 | - component: "ec-h264", | ||
| 199 | - direction: "encode", | ||
| 200 | - content: format!("{ew}x{eh}, {n} frames, 1 thread"), | ||
| 201 | - media: format!("{media_s:.1}s"), | ||
| 202 | - wall_ms: wall * 1000.0, | ||
| 203 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 204 | - }); | ||
| 205 | } else { | 214 | } else { |
| 206 | rows.push(missing("ec-h264", "encode")); | 215 | rows.push(missing("ec-h264", "encode")); |
| 207 | } | 216 | } |
| 208 | Ok(()) | 217 | Ok(()) |
| 209 | } | 218 | } |
| 210 | 219 | ||
| 211 | -/// `n` progressive frames of raw I420 at `w x h`, scaled and trimmed inside | 220 | +fn yuv420_frame_len(w: u32, h: u32, bytes_per_sample: usize) -> usize { |
| 212 | -/// ffmpeg. | 221 | + (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize * bytes_per_sample |
| 213 | -fn extract_yuv420p(src: &Path, w: u32, h: u32, n: u32) -> (Vec<u8>, u32, u32, u32) { | 222 | +} |
| 223 | + | ||
| 224 | +/// Up to `n` progressive frames at `w x h` in `pix_fmt`, scaled and trimmed | ||
| 225 | +/// inside ffmpeg from `SEEK_SECONDS` on. Empty when ffmpeg fails. | ||
| 226 | +fn extract_raw(src: &Path, w: u32, h: u32, n: u32, pix_fmt: &str) -> Vec<u8> { | ||
| 214 | let out = ec_testkit::ffmpeg() | 227 | let out = ec_testkit::ffmpeg() |
| 215 | .args(["-v", "error", "-ss", SEEK_SECONDS, "-i"]) | 228 | .args(["-v", "error", "-ss", SEEK_SECONDS, "-i"]) |
| 216 | .arg(src) | 229 | .arg(src) |
| @@ -220,19 +233,14 @@ fn extract_yuv420p(src: &Path, w: u32, h: u32, n: u32) -> (Vec<u8>, u32, u32, u3 | |||
| 220 | "-frames:v", | 233 | "-frames:v", |
| 221 | &n.to_string(), | 234 | &n.to_string(), |
| 222 | "-pix_fmt", | 235 | "-pix_fmt", |
| 223 | - "yuv420p", | 236 | + pix_fmt, |
| 224 | "-f", | 237 | "-f", |
| 225 | "rawvideo", | 238 | "rawvideo", |
| 226 | "-", | 239 | "-", |
| 227 | ]) | 240 | ]) |
| 228 | .output() | 241 | .output() |
| 229 | - .expect("ffmpeg extract yuv420p"); | 242 | + .expect("ffmpeg extract raw"); |
| 230 | - if !out.status.success() || out.stdout.is_empty() { | 243 | + if out.status.success() { out.stdout } else { Vec::new() } |
| 231 | - return (Vec::new(), w, h, 0); | ||
| 232 | - } | ||
| 233 | - let frame_len = (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize; | ||
| 234 | - let frames = (out.stdout.len() / frame_len) as u32; | ||
| 235 | - (out.stdout, w, h, frames) | ||
| 236 | } | 244 | } |
| 237 | 245 | ||
| 238 | fn parse_ratio(s: &str) -> Option<f64> { | 246 | fn parse_ratio(s: &str) -> Option<f64> { |
| @@ -251,16 +259,17 @@ fn bench_h265_encode(rows: &mut Vec<Row>) { | |||
| 251 | rows.push(missing("ec-h265", "encode")); | 259 | rows.push(missing("ec-h265", "encode")); |
| 252 | return; | 260 | return; |
| 253 | }; | 261 | }; |
| 254 | - let (planes, w, h, n) = extract_yuv420p(&src, 640, 360, 10); | 262 | + let (w, h) = (640, 360); |
| 263 | + let planes = extract_raw(&src, w, h, 10, "yuv420p"); | ||
| 264 | + let frame_len = yuv420_frame_len(w, h, 1); | ||
| 265 | + let n = (planes.len() / frame_len) as u32; | ||
| 255 | if n == 0 { | 266 | if n == 0 { |
| 256 | rows.push(missing("ec-h265", "encode")); | 267 | rows.push(missing("ec-h265", "encode")); |
| 257 | rows.push(missing("ec-h265", "decode")); | 268 | rows.push(missing("ec-h265", "decode")); |
| 258 | return; | 269 | return; |
| 259 | } | 270 | } |
| 260 | let enc = H265Encoder::new(H265Config::new(w, h)).expect("h265 encoder"); | 271 | let enc = H265Encoder::new(H265Config::new(w, h)).expect("h265 encoder"); |
| 261 | - let frame_len = (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize; | ||
| 262 | let cw = w.div_ceil(2); | 272 | let cw = w.div_ceil(2); |
| 263 | - let ch = h.div_ceil(2); | ||
| 264 | let mut aus = Vec::new(); | 273 | let mut aus = Vec::new(); |
| 265 | let start = Instant::now(); | 274 | let start = Instant::now(); |
| 266 | for frame in planes.chunks_exact(frame_len) { | 275 | for frame in planes.chunks_exact(frame_len) { |
| @@ -277,196 +286,115 @@ fn bench_h265_encode(rows: &mut Vec<Row>) { | |||
| 277 | ], | 286 | ], |
| 278 | ) | 287 | ) |
| 279 | .expect("i420 frame"); | 288 | .expect("i420 frame"); |
| 280 | - let _ = ch; // silence unused if plane_geometry ignores it | ||
| 281 | aus.push(enc.encode_idr(&vf).expect("h265 encode").au); | 289 | aus.push(enc.encode_idr(&vf).expect("h265 encode").au); |
| 282 | } | 290 | } |
| 283 | let wall = start.elapsed().as_secs_f64(); | 291 | let wall = start.elapsed().as_secs_f64(); |
| 284 | let media_s = n as f64 / 30.0; | 292 | let media_s = n as f64 / 30.0; |
| 285 | - rows.push(Row { | 293 | + rows.push(Row::timed("ec-h265", "encode", format!("{w}x{h}, {n} frames, IDR-only"), media_s, wall)); |
| 286 | - component: "ec-h265", | ||
| 287 | - direction: "encode", | ||
| 288 | - content: format!("{w}x{h}, {n} frames, IDR-only"), | ||
| 289 | - media: format!("{media_s:.1}s"), | ||
| 290 | - wall_ms: wall * 1000.0, | ||
| 291 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 292 | - }); | ||
| 293 | 294 | ||
| 294 | let start = Instant::now(); | 295 | let start = Instant::now(); |
| 295 | for au in &aus { | 296 | for au in &aus { |
| 296 | ec_h265::decode::decode_idr_au(au).expect("h265 decode"); | 297 | ec_h265::decode::decode_idr_au(au).expect("h265 decode"); |
| 297 | } | 298 | } |
| 298 | let wall = start.elapsed().as_secs_f64(); | 299 | let wall = start.elapsed().as_secs_f64(); |
| 299 | - rows.push(Row { | 300 | + rows.push(Row::timed("ec-h265", "decode", format!("{w}x{h}, {n} frames, own IDR stream"), media_s, wall)); |
| 300 | - component: "ec-h265", | ||
| 301 | - direction: "decode", | ||
| 302 | - content: format!("{w}x{h}, {n} frames, own IDR stream"), | ||
| 303 | - media: format!("{media_s:.1}s"), | ||
| 304 | - wall_ms: wall * 1000.0, | ||
| 305 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 306 | - }); | ||
| 307 | } | 301 | } |
| 308 | 302 | ||
| 309 | // --------------------------------------------------------------------------- | 303 | // --------------------------------------------------------------------------- |
| 310 | -// hardware av1: the GPU encoder, at the size his library is in. | 304 | +// hardware av1: the GPU encoder (`ec-hw`, VA-API), at 8 or 10 bits. |
| 311 | // --------------------------------------------------------------------------- | 305 | // --------------------------------------------------------------------------- |
| 312 | 306 | ||
| 313 | -/// AV1 encode on the GPU (`ec-hw`, VA-API). Skips as a row rather than a | 307 | +/// AV1 encode on the GPU. Skips as a row rather than a failure when there is |
| 314 | -/// failure when there is no VA device or the driver has no AV1 encode | 308 | +/// no VA device or the driver has no AV1 encode entrypoint -- a machine |
| 315 | -/// entrypoint -- a machine without one is not a slow machine. | 309 | +/// without one is not a slow machine. |
| 316 | -fn bench_hw_av1_encode(rows: &mut Vec<Row>) { | 310 | +#[cfg(target_os = "linux")] |
| 317 | - let Some(src) = real_video("h264").or_else(|| real_video("hevc")) else { | 311 | +fn bench_hw_av1_encode(rows: &mut Vec<Row>, ten_bit: bool) { |
| 318 | - rows.push(missing("ec-hw av1", "encode")); | 312 | + let (component, pix_fmt, bytes) = if ten_bit { |
| 319 | - return; | 313 | + ("ec-hw av1 10-bit", "yuv420p10le", 2) |
| 314 | + } else { | ||
| 315 | + ("ec-hw av1", "yuv420p", 1) | ||
| 320 | }; | 316 | }; |
| 321 | - let display = match ec_va::open() { | 317 | + let src = if ten_bit { |
| 322 | - Ok(display) => display, | 318 | + real_video("hevc").or_else(|| real_video("h264")) |
| 323 | - Err(e) => { | 319 | + } else { |
| 324 | - rows.push(missing_direction("ec-hw av1", "encode", &format!("no VA display ({e})"))); | 320 | + real_video("h264").or_else(|| real_video("hevc")) |
| 325 | - return; | ||
| 326 | - } | ||
| 327 | }; | 321 | }; |
| 328 | - let (planes, w, h, n) = extract_yuv420p(&src, 1920, 1080, 30); | 322 | + let Some(src) = src else { |
| 329 | - if n == 0 { | 323 | + rows.push(missing(component, "encode")); |
| 330 | - rows.push(missing("ec-hw av1", "encode")); | ||
| 331 | - return; | ||
| 332 | - } | ||
| 333 | - let mut cfg = ec_hw::EncoderConfig::new(ec_hw::EncCodec::Av1, w, h); | ||
| 334 | - cfg.rate_control = ec_hw::RateControlMode::ConstantQp { qp: 120 }; | ||
| 335 | - let mut enc = match ec_hw::Encoder::new(&display, cfg) { | ||
| 336 | - Ok(enc) => enc, | ||
| 337 | - Err(e) => { | ||
| 338 | - rows.push(missing_direction("ec-hw av1", "encode", &format!("driver refused ({e})"))); | ||
| 339 | - return; | ||
| 340 | - } | ||
| 341 | - }; | ||
| 342 | - let (cw, ch) = (w.div_ceil(2), h.div_ceil(2)); | ||
| 343 | - let frame_len = (w * h + 2 * cw * ch) as usize; | ||
| 344 | - let start = Instant::now(); | ||
| 345 | - let mut coded = 0usize; | ||
| 346 | - for (i, frame) in planes.chunks_exact(frame_len).enumerate() { | ||
| 347 | - let (y, rest) = frame.split_at((w * h) as usize); | ||
| 348 | - let (u, v) = rest.split_at(rest.len() / 2); | ||
| 349 | - let picture = ec_hw::I420 { | ||
| 350 | - y: y.to_vec(), | ||
| 351 | - u: u.to_vec(), | ||
| 352 | - v: v.to_vec(), | ||
| 353 | - width: w, | ||
| 354 | - height: h, | ||
| 355 | - }; | ||
| 356 | - let meta = ec_hw::FrameMetadata { | ||
| 357 | - timestamp: i as i64, | ||
| 358 | - force_keyframe: false, | ||
| 359 | - }; | ||
| 360 | - match enc.encode(&picture, meta) { | ||
| 361 | - Ok(out) => coded += out.data.len(), | ||
| 362 | - Err(e) => { | ||
| 363 | - rows.push(missing_direction("ec-hw av1", "encode", &format!("encode failed ({e})"))); | ||
| 364 | - return; | ||
| 365 | - } | ||
| 366 | - } | ||
| 367 | - } | ||
| 368 | - let wall = start.elapsed().as_secs_f64(); | ||
| 369 | - let media_s = n as f64 / 30.0; | ||
| 370 | - rows.push(Row { | ||
| 371 | - component: "ec-hw av1", | ||
| 372 | - direction: "encode", | ||
| 373 | - content: format!("{w}x{h}, {n} frames, CQP 120, {} kB", coded / 1000), | ||
| 374 | - media: format!("{media_s:.1}s"), | ||
| 375 | - wall_ms: wall * 1000.0, | ||
| 376 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 377 | - }); | ||
| 378 | -} | ||
| 379 | - | ||
| 380 | -/// The same row at 10 bits, which is the depth his own AV1 library is stored | ||
| 381 | -/// at (`yuv420p10le`, both films). Skips as a row when there is no VA device, | ||
| 382 | -/// no AV1 encode entrypoint, or no source to read. | ||
| 383 | -fn bench_hw_av1_encode_10bit(rows: &mut Vec<Row>) { | ||
| 384 | - let Some(src) = real_video("av1").or_else(|| real_video("hevc")).or_else(|| real_video("h264")) | ||
| 385 | - else { | ||
| 386 | - rows.push(missing("ec-hw av1 10-bit", "encode")); | ||
| 387 | return; | 324 | return; |
| 388 | }; | 325 | }; |
| 389 | let display = match ec_va::open() { | 326 | let display = match ec_va::open() { |
| 390 | Ok(display) => display, | 327 | Ok(display) => display, |
| 391 | Err(e) => { | 328 | Err(e) => { |
| 392 | - rows.push(missing_direction("ec-hw av1 10-bit", "encode", &format!("no VA display ({e})"))); | 329 | + rows.push(missing_direction(component, "encode", &format!("no VA display ({e})"))); |
| 393 | return; | 330 | return; |
| 394 | } | 331 | } |
| 395 | }; | 332 | }; |
| 396 | - let (w, h) = (1920u32, 1080u32); | 333 | + let (w, h) = (1920, 1080); |
| 397 | - let raw = extract_yuv420p10(&src, w, h, 30); | 334 | + let raw = extract_raw(&src, w, h, 30, pix_fmt); |
| 398 | - let (cw, ch) = (w.div_ceil(2), h.div_ceil(2)); | 335 | + let frame_len = yuv420_frame_len(w, h, bytes); |
| 399 | - let frame_len = ((w * h + 2 * cw * ch) * 2) as usize; | ||
| 400 | let n = (raw.len() / frame_len) as u32; | 336 | let n = (raw.len() / frame_len) as u32; |
| 401 | if n == 0 { | 337 | if n == 0 { |
| 402 | - rows.push(missing("ec-hw av1 10-bit", "encode")); | 338 | + rows.push(missing(component, "encode")); |
| 403 | return; | 339 | return; |
| 404 | } | 340 | } |
| 405 | - let mut cfg = ec_hw::EncoderConfig::new(ec_hw::EncCodec::Av1, w, h).ten_bit(); | 341 | + let mut cfg = ec_hw::EncoderConfig::new(ec_hw::EncCodec::Av1, w, h); |
| 342 | + if ten_bit { | ||
| 343 | + cfg = cfg.ten_bit(); | ||
| 344 | + } | ||
| 406 | cfg.rate_control = ec_hw::RateControlMode::ConstantQp { qp: 120 }; | 345 | cfg.rate_control = ec_hw::RateControlMode::ConstantQp { qp: 120 }; |
| 407 | let mut enc = match ec_hw::Encoder::new(&display, cfg) { | 346 | let mut enc = match ec_hw::Encoder::new(&display, cfg) { |
| 408 | Ok(enc) => enc, | 347 | Ok(enc) => enc, |
| 409 | Err(e) => { | 348 | Err(e) => { |
| 410 | - rows.push(missing_direction("ec-hw av1 10-bit", "encode", &format!("driver refused ({e})"))); | 349 | + rows.push(missing_direction(component, "encode", &format!("driver refused ({e})"))); |
| 411 | return; | 350 | return; |
| 412 | } | 351 | } |
| 413 | }; | 352 | }; |
| 414 | - let read = |s: &[u8]| -> Vec<u16> { | 353 | + let read16 = |s: &[u8]| -> Vec<u16> { |
| 415 | s.as_chunks::<2>().0.iter().map(|p| u16::from_le_bytes([p[0], p[1]])).collect() | 354 | s.as_chunks::<2>().0.iter().map(|p| u16::from_le_bytes([p[0], p[1]])).collect() |
| 416 | }; | 355 | }; |
| 417 | let start = Instant::now(); | 356 | let start = Instant::now(); |
| 418 | let mut coded = 0usize; | 357 | let mut coded = 0usize; |
| 419 | for (i, frame) in raw.chunks_exact(frame_len).enumerate() { | 358 | for (i, frame) in raw.chunks_exact(frame_len).enumerate() { |
| 420 | - let (y, rest) = frame.split_at((w * h * 2) as usize); | 359 | + let (y, rest) = frame.split_at((w * h) as usize * bytes); |
| 421 | let (u, v) = rest.split_at(rest.len() / 2); | 360 | let (u, v) = rest.split_at(rest.len() / 2); |
| 422 | - let picture = ec_hw::I420_16 { | ||
| 423 | - y: read(y), | ||
| 424 | - u: read(u), | ||
| 425 | - v: read(v), | ||
| 426 | - width: w, | ||
| 427 | - height: h, | ||
| 428 | - bit_depth: 10, | ||
| 429 | - }; | ||
| 430 | let meta = ec_hw::FrameMetadata { timestamp: i as i64, force_keyframe: false }; | 361 | let meta = ec_hw::FrameMetadata { timestamp: i as i64, force_keyframe: false }; |
| 431 | - match enc.encode_16(&picture, meta) { | 362 | + let result = if ten_bit { |
| 363 | + enc.encode_16( | ||
| 364 | + &ec_hw::I420_16 { | ||
| 365 | + y: read16(y), | ||
| 366 | + u: read16(u), | ||
| 367 | + v: read16(v), | ||
| 368 | + width: w, | ||
| 369 | + height: h, | ||
| 370 | + bit_depth: 10, | ||
| 371 | + }, | ||
| 372 | + meta, | ||
| 373 | + ) | ||
| 374 | + } else { | ||
| 375 | + enc.encode( | ||
| 376 | + &ec_hw::I420 { | ||
| 377 | + y: y.to_vec(), | ||
| 378 | + u: u.to_vec(), | ||
| 379 | + v: v.to_vec(), | ||
| 380 | + width: w, | ||
| 381 | + height: h, | ||
| 382 | + }, | ||
| 383 | + meta, | ||
| 384 | + ) | ||
| 385 | + }; | ||
| 386 | + match result { | ||
| 432 | Ok(out) => coded += out.data.len(), | 387 | Ok(out) => coded += out.data.len(), |
| 433 | Err(e) => { | 388 | Err(e) => { |
| 434 | - rows.push(missing_direction("ec-hw av1 10-bit", "encode", &format!("encode failed ({e})"))); | 389 | + rows.push(missing_direction(component, "encode", &format!("encode failed ({e})"))); |
| 435 | return; | 390 | return; |
| 436 | } | 391 | } |
| 437 | } | 392 | } |
| 438 | } | 393 | } |
| 439 | let wall = start.elapsed().as_secs_f64(); | 394 | let wall = start.elapsed().as_secs_f64(); |
| 440 | let media_s = f64::from(n) / 30.0; | 395 | let media_s = f64::from(n) / 30.0; |
| 441 | - rows.push(Row { | 396 | + let content = format!("{w}x{h} {pix_fmt}, {n} frames, CQP 120, {} kB", coded / 1000); |
| 442 | - component: "ec-hw av1 10-bit", | 397 | + rows.push(Row::timed(component, "encode", content, media_s, wall)); |
| 443 | - direction: "encode", | ||
| 444 | - content: format!("{w}x{h} yuv420p10le, {n} frames from 00:00:30, CQP 120, {} kB", coded / 1000), | ||
| 445 | - media: format!("{media_s:.1}s"), | ||
| 446 | - wall_ms: wall * 1000.0, | ||
| 447 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 448 | - }); | ||
| 449 | -} | ||
| 450 | - | ||
| 451 | -/// `extract_yuv420p` at ten bits, planar 16-bit little endian, seeked | ||
| 452 | -/// into the clip: frame 0 of a film is its black leader, and a black leader codes | ||
| 453 | -/// to nothing and benchmarks nothing. | ||
| 454 | -fn extract_yuv420p10(src: &Path, w: u32, h: u32, n: u32) -> Vec<u8> { | ||
| 455 | - let out = ec_testkit::ffmpeg() | ||
| 456 | - .args(["-v", "error", "-ss", SEEK_SECONDS, "-i"]) | ||
| 457 | - .arg(src) | ||
| 458 | - .args([ | ||
| 459 | - "-vf", &format!("scale={w}:{h}"), | ||
| 460 | - "-frames:v", &n.to_string(), | ||
| 461 | - "-pix_fmt", "yuv420p10le", | ||
| 462 | - "-f", "rawvideo", "-", | ||
| 463 | - ]) | ||
| 464 | - .output() | ||
| 465 | - .expect("ffmpeg extract yuv420p10le"); | ||
| 466 | - if !out.status.success() { | ||
| 467 | - return Vec::new(); | ||
| 468 | - } | ||
| 469 | - out.stdout | ||
| 470 | } | 398 | } |
| 471 | 399 | ||
| 472 | // --------------------------------------------------------------------------- | 400 | // --------------------------------------------------------------------------- |
| @@ -480,7 +408,10 @@ fn bench_av1_encode(rows: &mut Vec<Row>) { | |||
| 480 | return; | 408 | return; |
| 481 | }; | 409 | }; |
| 482 | // AV1's block grid is 32x32 superblocks: pick a size already a multiple of it. | 410 | // AV1's block grid is 32x32 superblocks: pick a size already a multiple of it. |
| 483 | - let (planes, w, h, n) = extract_yuv420p(&src, 640, 384, 10); | 411 | + let (w, h) = (640, 384); |
| 412 | + let planes = extract_raw(&src, w, h, 10, "yuv420p"); | ||
| 413 | + let frame_len = yuv420_frame_len(w, h, 1); | ||
| 414 | + let n = (planes.len() / frame_len) as u32; | ||
| 484 | if n == 0 { | 415 | if n == 0 { |
| 485 | rows.push(missing("ec-av1", "encode")); | 416 | rows.push(missing("ec-av1", "encode")); |
| 486 | rows.push(missing("ec-av1", "decode")); | 417 | rows.push(missing("ec-av1", "decode")); |
| @@ -530,7 +461,6 @@ fn bench_av1_encode(rows: &mut Vec<Row>) { | |||
| 530 | None => Av1Encoder::with_speed(cfg, speed).expect("av1 encoder"), | 461 | None => Av1Encoder::with_speed(cfg, speed).expect("av1 encoder"), |
| 531 | Some(p) => Av1Encoder::with_pyramid(cfg, p).expect("av1 encoder"), | 462 | Some(p) => Av1Encoder::with_pyramid(cfg, p).expect("av1 encoder"), |
| 532 | }; | 463 | }; |
| 533 | - let frame_len = (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize; | ||
| 534 | let mut stream = Vec::new(); | 464 | let mut stream = Vec::new(); |
| 535 | let mut hidden = 0usize; | 465 | let mut hidden = 0usize; |
| 536 | let start = Instant::now(); | 466 | let start = Instant::now(); |
| @@ -571,17 +501,11 @@ fn bench_av1_encode(rows: &mut Vec<Row>) { | |||
| 571 | }; | 501 | }; |
| 572 | let fps = if wall > 0.0 { f64::from(n) / wall } else { 0.0 }; | 502 | let fps = if wall > 0.0 { f64::from(n) / wall } else { 0.0 }; |
| 573 | let bytes_per_frame = stream.len() as f64 / f64::from(n); | 503 | let bytes_per_frame = stream.len() as f64 / f64::from(n); |
| 574 | - rows.push(Row { | 504 | + let content = format!( |
| 575 | - component: "ec-av1", | 505 | + "speed {speed} [{levers}], {w}x{h}, {n} frames, gop=10, {coded_under}, \ |
| 576 | - direction: "encode", | 506 | + {hidden} hidden, {fps:.1} fps, {bytes_per_frame:.0} B/frame" |
| 577 | - content: format!( | 507 | + ); |
| 578 | - "speed {speed} [{levers}], {w}x{h}, {n} frames, gop=10, {coded_under}, \ | 508 | + rows.push(Row::timed("ec-av1", "encode", content, media_s, wall)); |
| 579 | - {hidden} hidden, {fps:.1} fps, {bytes_per_frame:.0} B/frame" | ||
| 580 | - ), | ||
| 581 | - media: format!("{media_s:.1}s"), | ||
| 582 | - wall_ms: wall * 1000.0, | ||
| 583 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 584 | - }); | ||
| 585 | if first_stream.is_empty() { | 509 | if first_stream.is_empty() { |
| 586 | first_stream = stream; | 510 | first_stream = stream; |
| 587 | } | 511 | } |
| @@ -595,14 +519,7 @@ fn bench_av1_encode(rows: &mut Vec<Row>) { | |||
| 595 | let pictures = ec_av1::stream::decode_stream(&stream).expect("av1 decode_stream"); | 519 | let pictures = ec_av1::stream::decode_stream(&stream).expect("av1 decode_stream"); |
| 596 | let wall = start.elapsed().as_secs_f64(); | 520 | let wall = start.elapsed().as_secs_f64(); |
| 597 | assert_eq!(pictures.len(), n as usize, "decode_stream frame count"); | 521 | assert_eq!(pictures.len(), n as usize, "decode_stream frame count"); |
| 598 | - rows.push(Row { | 522 | + rows.push(Row::timed("ec-av1", "decode", format!("{w}x{h}, {n} frames, gop=10"), media_s, wall)); |
| 599 | - component: "ec-av1", | ||
| 600 | - direction: "decode", | ||
| 601 | - content: format!("{w}x{h}, {n} frames, gop=10"), | ||
| 602 | - media: format!("{media_s:.1}s"), | ||
| 603 | - wall_ms: wall * 1000.0, | ||
| 604 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 605 | - }); | ||
| 606 | } | 523 | } |
| 607 | 524 | ||
| 608 | // --------------------------------------------------------------------------- | 525 | // --------------------------------------------------------------------------- |
| @@ -719,14 +636,7 @@ fn bench_audio_encode(rows: &mut Vec<Row>) { | |||
| 719 | .expect("opus encode"); | 636 | .expect("opus encode"); |
| 720 | } | 637 | } |
| 721 | let wall = start.elapsed().as_secs_f64(); | 638 | let wall = start.elapsed().as_secs_f64(); |
| 722 | - rows.push(Row { | 639 | + rows.push(Row::timed("ec-opus", "encode", content.clone(), media_s, wall)); |
| 723 | - component: "ec-opus", | ||
| 724 | - direction: "encode", | ||
| 725 | - content: content.clone(), | ||
| 726 | - media: format!("{media_s:.1}s"), | ||
| 727 | - wall_ms: wall * 1000.0, | ||
| 728 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 729 | - }); | ||
| 730 | } | 640 | } |
| 731 | 641 | ||
| 732 | // vorbis: quality 0.6, the level the oracle tests already encode at. | 642 | // vorbis: quality 0.6, the level the oracle tests already encode at. |
| @@ -751,14 +661,7 @@ fn bench_audio_encode(rows: &mut Vec<Row>) { | |||
| 751 | } | 661 | } |
| 752 | let wall = start.elapsed().as_secs_f64(); | 662 | let wall = start.elapsed().as_secs_f64(); |
| 753 | let _ = n; | 663 | let _ = n; |
| 754 | - rows.push(Row { | 664 | + rows.push(Row::timed("ec-vorbis", "encode", content.clone(), media_s, wall)); |
| 755 | - component: "ec-vorbis", | ||
| 756 | - direction: "encode", | ||
| 757 | - content: content.clone(), | ||
| 758 | - media: format!("{media_s:.1}s"), | ||
| 759 | - wall_ms: wall * 1000.0, | ||
| 760 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 761 | - }); | ||
| 762 | } | 665 | } |
| 763 | 666 | ||
| 764 | // aac: 128 kbit/s, raw (no ADTS wrap) -- the default config. | 667 | // aac: 128 kbit/s, raw (no ADTS wrap) -- the default config. |
| @@ -769,14 +672,7 @@ fn bench_audio_encode(rows: &mut Vec<Row>) { | |||
| 769 | enc.finish(); | 672 | enc.finish(); |
| 770 | while enc.next_packet().is_ok() {} | 673 | while enc.next_packet().is_ok() {} |
| 771 | let wall = start.elapsed().as_secs_f64(); | 674 | let wall = start.elapsed().as_secs_f64(); |
| 772 | - rows.push(Row { | 675 | + rows.push(Row::timed("ec-aac", "encode", content.clone(), media_s, wall)); |
| 773 | - component: "ec-aac", | ||
| 774 | - direction: "encode", | ||
| 775 | - content: content.clone(), | ||
| 776 | - media: format!("{media_s:.1}s"), | ||
| 777 | - wall_ms: wall * 1000.0, | ||
| 778 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 779 | - }); | ||
| 780 | } | 676 | } |
| 781 | 677 | ||
| 782 | // mp3: CBR 192 kbit/s, the incumbent-matching default the tests gate on. | 678 | // mp3: CBR 192 kbit/s, the incumbent-matching default the tests gate on. |
| @@ -791,14 +687,7 @@ fn bench_audio_encode(rows: &mut Vec<Row>) { | |||
| 791 | enc.finish(); | 687 | enc.finish(); |
| 792 | while enc.next_packet().is_ok() {} | 688 | while enc.next_packet().is_ok() {} |
| 793 | let wall = start.elapsed().as_secs_f64(); | 689 | let wall = start.elapsed().as_secs_f64(); |
| 794 | - rows.push(Row { | 690 | + rows.push(Row::timed("ec-mp3", "encode", content.clone(), media_s, wall)); |
| 795 | - component: "ec-mp3", | ||
| 796 | - direction: "encode", | ||
| 797 | - content: content.clone(), | ||
| 798 | - media: format!("{media_s:.1}s"), | ||
| 799 | - wall_ms: wall * 1000.0, | ||
| 800 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 801 | - }); | ||
| 802 | } | 691 | } |
| 803 | 692 | ||
| 804 | // flac: single-shot, default config (4096-sample blocks, LPC-12), 16-bit. | 693 | // flac: single-shot, default config (4096-sample blocks, LPC-12), 16-bit. |
| @@ -811,14 +700,7 @@ fn bench_audio_encode(rows: &mut Vec<Row>) { | |||
| 811 | let start = Instant::now(); | 700 | let start = Instant::now(); |
| 812 | let _ = ec_flac::encode(&cfg, &samples, channels, 16, rate).expect("flac encode"); | 701 | let _ = ec_flac::encode(&cfg, &samples, channels, 16, rate).expect("flac encode"); |
| 813 | let wall = start.elapsed().as_secs_f64(); | 702 | let wall = start.elapsed().as_secs_f64(); |
| 814 | - rows.push(Row { | 703 | + rows.push(Row::timed("ec-flac", "encode", content.clone(), media_s, wall)); |
| 815 | - component: "ec-flac", | ||
| 816 | - direction: "encode", | ||
| 817 | - content: content.clone(), | ||
| 818 | - media: format!("{media_s:.1}s"), | ||
| 819 | - wall_ms: wall * 1000.0, | ||
| 820 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 821 | - }); | ||
| 822 | } | 704 | } |
| 823 | 705 | ||
| 824 | // alac: 4096-sample frames, 16-bit -- same shape the round-trip tests use. | 706 | // alac: 4096-sample frames, 16-bit -- same shape the round-trip tests use. |
| @@ -834,14 +716,7 @@ fn bench_audio_encode(rows: &mut Vec<Row>) { | |||
| 834 | enc.encode_frame(chunk).expect("alac frame"); | 716 | enc.encode_frame(chunk).expect("alac frame"); |
| 835 | } | 717 | } |
| 836 | let wall = start.elapsed().as_secs_f64(); | 718 | let wall = start.elapsed().as_secs_f64(); |
| 837 | - rows.push(Row { | 719 | + rows.push(Row::timed("ec-alac", "encode", content.clone(), media_s, wall)); |
| 838 | - component: "ec-alac", | ||
| 839 | - direction: "encode", | ||
| 840 | - content: content.clone(), | ||
| 841 | - media: format!("{media_s:.1}s"), | ||
| 842 | - wall_ms: wall * 1000.0, | ||
| 843 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 844 | - }); | ||
| 845 | } | 720 | } |
| 846 | 721 | ||
| 847 | // ac3: 192 kbit/s -- only if the source's channel count is one A/52 codes. | 722 | // ac3: 192 kbit/s -- only if the source's channel count is one A/52 codes. |
| @@ -863,14 +738,7 @@ fn bench_audio_encode(rows: &mut Vec<Row>) { | |||
| 863 | } | 738 | } |
| 864 | } | 739 | } |
| 865 | let wall = start.elapsed().as_secs_f64(); | 740 | let wall = start.elapsed().as_secs_f64(); |
| 866 | - rows.push(Row { | 741 | + rows.push(Row::timed("ec-ac3", "encode", content, media_s, wall)); |
| 867 | - component: "ec-ac3", | ||
| 868 | - direction: "encode", | ||
| 869 | - content, | ||
| 870 | - media: format!("{media_s:.1}s"), | ||
| 871 | - wall_ms: wall * 1000.0, | ||
| 872 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 873 | - }); | ||
| 874 | } else { | 742 | } else { |
| 875 | rows.push(missing_direction( | 743 | rows.push(missing_direction( |
| 876 | "ec-ac3", | 744 | "ec-ac3", |
| @@ -930,14 +798,7 @@ fn bench_truehd(rows: &mut Vec<Row>) { | |||
| 930 | thd.extend_from_slice(&pkt.data); | 798 | thd.extend_from_slice(&pkt.data); |
| 931 | } | 799 | } |
| 932 | let wall = start.elapsed().as_secs_f64(); | 800 | let wall = start.elapsed().as_secs_f64(); |
| 933 | - rows.push(Row { | 801 | + rows.push(Row::timed("ec-truehd", "encode", format!("{media_s:.1}s wav16 stereo @ {rate}Hz"), media_s, wall)); |
| 934 | - component: "ec-truehd", | ||
| 935 | - direction: "encode", | ||
| 936 | - content: format!("{media_s:.1}s wav16 stereo @ {rate}Hz"), | ||
| 937 | - media: format!("{media_s:.1}s"), | ||
| 938 | - wall_ms: wall * 1000.0, | ||
| 939 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 940 | - }); | ||
| 941 | 802 | ||
| 942 | let mut dec = ec_truehd::TrueHdDecoder::new(); | 803 | let mut dec = ec_truehd::TrueHdDecoder::new(); |
| 943 | let start = Instant::now(); | 804 | let start = Instant::now(); |
| @@ -957,14 +818,7 @@ fn bench_truehd(rows: &mut Vec<Row>) { | |||
| 957 | } | 818 | } |
| 958 | let wall = start.elapsed().as_secs_f64(); | 819 | let wall = start.elapsed().as_secs_f64(); |
| 959 | let media_s = samples as f64 / f64::from(rate); | 820 | let media_s = samples as f64 / f64::from(rate); |
| 960 | - rows.push(Row { | 821 | + rows.push(Row::timed("ec-truehd", "decode", "own encoded stream, stereo".to_string(), media_s, wall)); |
| 961 | - component: "ec-truehd", | ||
| 962 | - direction: "decode", | ||
| 963 | - content: "own encoded stream, stereo".to_string(), | ||
| 964 | - media: format!("{media_s:.1}s"), | ||
| 965 | - wall_ms: wall * 1000.0, | ||
| 966 | - rtf: (wall > 0.0).then_some(media_s / wall), | ||
| 967 | - }); | ||
| 968 | } | 822 | } |
| 969 | 823 | ||
| 970 | // --------------------------------------------------------------------------- | 824 | // --------------------------------------------------------------------------- |