Merge branch 'simplify/b19' into simplify/w1a
Browse files at this commit1 changed file +34 -31
- tools/ec-bench/src/main.rs +34 -31
tools/ec-bench/src/main.rsmodified+34 -31
| @@ -37,15 +37,15 @@ struct Row { | |||
| 37 | rtf: Option<f64>, | 37 | rtf: Option<f64>, |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | -fn main() { | 40 | +fn main() -> ec_core::Result<()> { |
| 41 | let mut rows = Vec::new(); | 41 | let mut rows = Vec::new(); |
| 42 | 42 | ||
| 43 | - bench_h264(&mut rows); | 43 | + bench_h264(&mut rows)?; |
| 44 | bench_h265_encode(&mut rows); | 44 | bench_h265_encode(&mut rows); |
| 45 | bench_av1_encode(&mut rows); | 45 | bench_av1_encode(&mut rows); |
| 46 | bench_hw_av1_encode(&mut rows); | 46 | bench_hw_av1_encode(&mut rows); |
| 47 | bench_hw_av1_encode_10bit(&mut rows); | 47 | bench_hw_av1_encode_10bit(&mut rows); |
| 48 | - bench_audio_decode(&mut rows); | 48 | + bench_audio_decode(&mut rows)?; |
| 49 | bench_audio_encode(&mut rows); | 49 | bench_audio_encode(&mut rows); |
| 50 | bench_truehd(&mut rows); | 50 | bench_truehd(&mut rows); |
| 51 | bench_container_demux(&mut rows); | 51 | bench_container_demux(&mut rows); |
| @@ -70,23 +70,29 @@ fn main() { | |||
| 70 | r.component, r.direction, r.content, r.media, r.wall_ms, rtf | 70 | r.component, r.direction, r.content, r.media, r.wall_ms, rtf |
| 71 | ); | 71 | ); |
| 72 | } | 72 | } |
| 73 | + Ok(()) | ||
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | // --------------------------------------------------------------------------- | 76 | // --------------------------------------------------------------------------- |
| 76 | // media discovery | 77 | // media discovery |
| 77 | // --------------------------------------------------------------------------- | 78 | // --------------------------------------------------------------------------- |
| 78 | 79 | ||
| 79 | -fn fixtures() -> PathBuf { | 80 | +fn media_dir() -> PathBuf { |
| 80 | - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures") | 81 | + std::env::args_os() |
| 82 | + .nth(1) | ||
| 83 | + .map_or_else(ec_testkit::root, PathBuf::from) | ||
| 81 | } | 84 | } |
| 82 | 85 | ||
| 86 | +const SEEK_SECONDS: &str = "30"; | ||
| 87 | + | ||
| 83 | fn real_video(codec: &str) -> Option<PathBuf> { | 88 | fn real_video(codec: &str) -> Option<PathBuf> { |
| 84 | let name = match codec { | 89 | let name = match codec { |
| 85 | "h264" => "open/sintel_trailer-1080p.mp4", | 90 | "h264" => "open/sintel_trailer-1080p.mp4", |
| 86 | "hevc" => "derived/sintel720-x265-main10.mp4", | 91 | "hevc" => "derived/sintel720-x265-main10.mp4", |
| 87 | _ => return None, | 92 | _ => return None, |
| 88 | }; | 93 | }; |
| 89 | - Some(ec_testkit::fixture(name)) | 94 | + let path = media_dir().join(name); |
| 95 | + path.exists().then_some(path) | ||
| 90 | } | 96 | } |
| 91 | 97 | ||
| 92 | fn ffprobe_field(path: &Path, stream: &str, key: &str) -> Option<String> { | 98 | fn ffprobe_field(path: &Path, stream: &str, key: &str) -> Option<String> { |
| @@ -108,11 +114,11 @@ fn ffprobe_field(path: &Path, stream: &str, key: &str) -> Option<String> { | |||
| 108 | // h264: decode (real film, 10s) + encode (raw planes from the same clip) | 114 | // h264: decode (real film, 10s) + encode (raw planes from the same clip) |
| 109 | // --------------------------------------------------------------------------- | 115 | // --------------------------------------------------------------------------- |
| 110 | 116 | ||
| 111 | -fn bench_h264(rows: &mut Vec<Row>) { | 117 | +fn bench_h264(rows: &mut Vec<Row>) -> ec_core::Result<()> { |
| 112 | let Some(src) = real_video("h264") else { | 118 | let Some(src) = real_video("h264") else { |
| 113 | rows.push(missing("ec-h264", "decode")); | 119 | rows.push(missing("ec-h264", "decode")); |
| 114 | rows.push(missing("ec-h264", "encode")); | 120 | rows.push(missing("ec-h264", "encode")); |
| 115 | - return; | 121 | + return Ok(()); |
| 116 | }; | 122 | }; |
| 117 | let w: u32 = ffprobe_field(&src, "v:0", "width") | 123 | let w: u32 = ffprobe_field(&src, "v:0", "width") |
| 118 | .and_then(|s| s.parse().ok()) | 124 | .and_then(|s| s.parse().ok()) |
| @@ -143,15 +149,15 @@ fn bench_h264(rows: &mut Vec<Row>) { | |||
| 143 | let mut dec = H264Decoder::new(); | 149 | let mut dec = H264Decoder::new(); |
| 144 | let mut frames = 0u64; | 150 | let mut frames = 0u64; |
| 145 | for nal in AnnexBIter::new(&bytes) { | 151 | for nal in AnnexBIter::new(&bytes) { |
| 146 | - if let Ok(NalOutcome::PictureBoundary) = dec.push_nal(nal) { | 152 | + if let NalOutcome::PictureBoundary = dec.push_nal(nal)? { |
| 147 | - let _ = dec.end_picture(); | 153 | + dec.end_picture()?; |
| 148 | - let _ = dec.push_nal(nal); | 154 | + dec.push_nal(nal)?; |
| 149 | } | 155 | } |
| 150 | while dec.next_frame().is_some() { | 156 | while dec.next_frame().is_some() { |
| 151 | frames += 1; | 157 | frames += 1; |
| 152 | } | 158 | } |
| 153 | } | 159 | } |
| 154 | - let _ = dec.flush(); | 160 | + dec.flush()?; |
| 155 | while dec.next_frame().is_some() { | 161 | while dec.next_frame().is_some() { |
| 156 | frames += 1; | 162 | frames += 1; |
| 157 | } | 163 | } |
| @@ -199,13 +205,14 @@ fn bench_h264(rows: &mut Vec<Row>) { | |||
| 199 | } else { | 205 | } else { |
| 200 | rows.push(missing("ec-h264", "encode")); | 206 | rows.push(missing("ec-h264", "encode")); |
| 201 | } | 207 | } |
| 208 | + Ok(()) | ||
| 202 | } | 209 | } |
| 203 | 210 | ||
| 204 | /// `n` progressive frames of raw I420 at `w x h`, scaled and trimmed inside | 211 | /// `n` progressive frames of raw I420 at `w x h`, scaled and trimmed inside |
| 205 | /// ffmpeg. | 212 | /// ffmpeg. |
| 206 | fn extract_yuv420p(src: &Path, w: u32, h: u32, n: u32) -> (Vec<u8>, u32, u32, u32) { | 213 | fn extract_yuv420p(src: &Path, w: u32, h: u32, n: u32) -> (Vec<u8>, u32, u32, u32) { |
| 207 | let out = ec_testkit::ffmpeg() | 214 | let out = ec_testkit::ffmpeg() |
| 208 | - .args(["-v", "error", "-i"]) | 215 | + .args(["-v", "error", "-ss", SEEK_SECONDS, "-i"]) |
| 209 | .arg(src) | 216 | .arg(src) |
| 210 | .args([ | 217 | .args([ |
| 211 | "-vf", | 218 | "-vf", |
| @@ -250,11 +257,7 @@ fn bench_h265_encode(rows: &mut Vec<Row>) { | |||
| 250 | rows.push(missing("ec-h265", "decode")); | 257 | rows.push(missing("ec-h265", "decode")); |
| 251 | return; | 258 | return; |
| 252 | } | 259 | } |
| 253 | - let mut cfg = H265Config::new(w, h); | 260 | + let enc = H265Encoder::new(H265Config::new(w, h)).expect("h265 encoder"); |
| 254 | - // A/B knob for the RDOQ estimated-bit-cost path (off by default, matching | ||
| 255 | - // the encoder's own default): EC_H265_RDOQ_ESTIMATE=1 to measure it. | ||
| 256 | - cfg.rdoq_estimate = std::env::var("EC_H265_RDOQ_ESTIMATE").is_ok_and(|v| v != "0"); | ||
| 257 | - let enc = H265Encoder::new(cfg).expect("h265 encoder"); | ||
| 258 | let frame_len = (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize; | 261 | let frame_len = (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize; |
| 259 | let cw = w.div_ceil(2); | 262 | let cw = w.div_ceil(2); |
| 260 | let ch = h.div_ceil(2); | 263 | let ch = h.div_ceil(2); |
| @@ -438,19 +441,19 @@ fn bench_hw_av1_encode_10bit(rows: &mut Vec<Row>) { | |||
| 438 | rows.push(Row { | 441 | rows.push(Row { |
| 439 | component: "ec-hw av1 10-bit", | 442 | component: "ec-hw av1 10-bit", |
| 440 | direction: "encode", | 443 | direction: "encode", |
| 441 | - content: format!("{w}x{h} yuv420p10le, {n} frames from 00:01:00, CQP 120, {} kB", coded / 1000), | 444 | + content: format!("{w}x{h} yuv420p10le, {n} frames from 00:00:30, CQP 120, {} kB", coded / 1000), |
| 442 | media: format!("{media_s:.1}s"), | 445 | media: format!("{media_s:.1}s"), |
| 443 | wall_ms: wall * 1000.0, | 446 | wall_ms: wall * 1000.0, |
| 444 | rtf: (wall > 0.0).then_some(media_s / wall), | 447 | rtf: (wall > 0.0).then_some(media_s / wall), |
| 445 | }); | 448 | }); |
| 446 | } | 449 | } |
| 447 | 450 | ||
| 448 | -/// `extract_yuv420p` at ten bits, planar 16-bit little endian, seeked a | 451 | +/// `extract_yuv420p` at ten bits, planar 16-bit little endian, seeked |
| 449 | -/// minute in: frame 0 of a film is its black leader, and a black leader codes | 452 | +/// into the clip: frame 0 of a film is its black leader, and a black leader codes |
| 450 | /// to nothing and benchmarks nothing. | 453 | /// to nothing and benchmarks nothing. |
| 451 | fn extract_yuv420p10(src: &Path, w: u32, h: u32, n: u32) -> Vec<u8> { | 454 | fn extract_yuv420p10(src: &Path, w: u32, h: u32, n: u32) -> Vec<u8> { |
| 452 | let out = ec_testkit::ffmpeg() | 455 | let out = ec_testkit::ffmpeg() |
| 453 | - .args(["-v", "error", "-ss", "60", "-i"]) | 456 | + .args(["-v", "error", "-ss", SEEK_SECONDS, "-i"]) |
| 454 | .arg(src) | 457 | .arg(src) |
| 455 | .args([ | 458 | .args([ |
| 456 | "-vf", &format!("scale={w}:{h}"), | 459 | "-vf", &format!("scale={w}:{h}"), |
| @@ -607,12 +610,12 @@ fn bench_av1_encode(rows: &mut Vec<Row>) { | |||
| 607 | // it wraps (mp3/flac/aac/alac/ac3/truehd/opus/vorbis via ogg/mp4/matroska). | 610 | // it wraps (mp3/flac/aac/alac/ac3/truehd/opus/vorbis via ogg/mp4/matroska). |
| 608 | // --------------------------------------------------------------------------- | 611 | // --------------------------------------------------------------------------- |
| 609 | 612 | ||
| 610 | -fn bench_audio_decode(rows: &mut Vec<Row>) { | 613 | +fn bench_audio_decode(rows: &mut Vec<Row>) -> ec_core::Result<()> { |
| 611 | let mut candidates: Vec<PathBuf> = Vec::new(); | 614 | let mut candidates: Vec<PathBuf> = Vec::new(); |
| 612 | - if let Ok(entries) = std::fs::read_dir(fixtures().join("audio")) { | 615 | + if let Ok(entries) = std::fs::read_dir(media_dir().join("audio")) { |
| 613 | candidates.extend(entries.flatten().map(|e| e.path())); | 616 | candidates.extend(entries.flatten().map(|e| e.path())); |
| 614 | } | 617 | } |
| 615 | - candidates.push(ec_testkit::fixture("open/fate/ac3/monsters_inc_5.1_448_small.ac3")); | 618 | + candidates.push(media_dir().join("open/fate/ac3/monsters_inc_5.1_448_small.ac3")); |
| 616 | candidates.sort(); | 619 | candidates.sort(); |
| 617 | candidates.dedup(); | 620 | candidates.dedup(); |
| 618 | 621 | ||
| @@ -634,15 +637,14 @@ fn bench_audio_decode(rows: &mut Vec<Row>) { | |||
| 634 | match reader.next_packet() { | 637 | match reader.next_packet() { |
| 635 | Ok(pkt) if pkt.stream == stream => { | 638 | Ok(pkt) if pkt.stream == stream => { |
| 636 | out.clear(); | 639 | out.clear(); |
| 637 | - if dec.decode(&pkt, &mut out).is_ok() { | 640 | + dec.decode(&pkt, &mut out)?; |
| 638 | - samples += (out.len() / dec.channels().max(1)) as u64; | 641 | + samples += (out.len() / dec.channels().max(1)) as u64; |
| 639 | - } | ||
| 640 | } | 642 | } |
| 641 | Ok(_) => {} | 643 | Ok(_) => {} |
| 642 | Err(_) => break, | 644 | Err(_) => break, |
| 643 | } | 645 | } |
| 644 | } | 646 | } |
| 645 | - let _ = dec.flush(&mut out); | 647 | + dec.flush(&mut out)?; |
| 646 | let wall = start.elapsed().as_secs_f64(); | 648 | let wall = start.elapsed().as_secs_f64(); |
| 647 | let media_s = samples as f64 / dec.sample_rate().max(1) as f64; | 649 | let media_s = samples as f64 / dec.sample_rate().max(1) as f64; |
| 648 | let name = path.file_name().unwrap().to_string_lossy().into_owned(); | 650 | let name = path.file_name().unwrap().to_string_lossy().into_owned(); |
| @@ -655,6 +657,7 @@ fn bench_audio_decode(rows: &mut Vec<Row>) { | |||
| 655 | rtf: (wall > 0.0 && media_s > 0.0).then_some(media_s / wall), | 657 | rtf: (wall > 0.0 && media_s > 0.0).then_some(media_s / wall), |
| 656 | }); | 658 | }); |
| 657 | } | 659 | } |
| 660 | + Ok(()) | ||
| 658 | } | 661 | } |
| 659 | 662 | ||
| 660 | // --------------------------------------------------------------------------- | 663 | // --------------------------------------------------------------------------- |
| @@ -666,7 +669,7 @@ fn bench_audio_decode(rows: &mut Vec<Row>) { | |||
| 666 | /// `seconds` of real interleaved `f32` PCM, decoded through `ec-probe`'s own | 669 | /// `seconds` of real interleaved `f32` PCM, decoded through `ec-probe`'s own |
| 667 | /// `Reader`/`AudioDecoder` route (the same one `bench_audio_decode` drives). | 670 | /// `Reader`/`AudioDecoder` route (the same one `bench_audio_decode` drives). |
| 668 | fn real_pcm(seconds: f64) -> Option<(Vec<f32>, u32, usize)> { | 671 | fn real_pcm(seconds: f64) -> Option<(Vec<f32>, u32, usize)> { |
| 669 | - let path = ec_testkit::fixture("audio/wav16-stereo-48000.wav"); | 672 | + let path = media_dir().join("audio/wav16-stereo-48000.wav"); |
| 670 | let mut reader = Reader::open(&path).ok()?; | 673 | let mut reader = Reader::open(&path).ok()?; |
| 671 | let stream = reader.default_stream(MediaType::Audio)?.index; | 674 | let stream = reader.default_stream(MediaType::Audio)?.index; |
| 672 | let mut dec = reader.make_decoder(stream).ok()?; | 675 | let mut dec = reader.make_decoder(stream).ok()?; |
| @@ -987,7 +990,7 @@ fn format_duration(path: &Path) -> Option<String> { | |||
| 987 | 990 | ||
| 988 | fn bench_container_demux(rows: &mut Vec<Row>) { | 991 | fn bench_container_demux(rows: &mut Vec<Row>) { |
| 989 | for (component, ext) in [("ec-matroska", "mkv"), ("ec-mp4", "mp4")] { | 992 | for (component, ext) in [("ec-matroska", "mkv"), ("ec-mp4", "mp4")] { |
| 990 | - let Some(src) = [ec_testkit::root().join("open"), ec_testkit::root().join("derived")] | 993 | + let Some(src) = [media_dir().join("open"), media_dir().join("derived")] |
| 991 | .into_iter() | 994 | .into_iter() |
| 992 | .filter_map(|d| std::fs::read_dir(d).ok()) | 995 | .filter_map(|d| std::fs::read_dir(d).ok()) |
| 993 | .flatten() | 996 | .flatten() |