forge
Explore
Log in

Don't you dare go Hollow

ec-hw intra_rate: a CBR point also passes when it lands no further from the ask than ffmpeg's own VA/Vulkan encoder on the same input (intra-only CBR is beyond this driver at low rates: ffmpeg h264_vaapi GOP 1 +67.6/+36.5/+26.3%, ours +52.5/+14.4/+0.1%)

Browse files at this commit

7aeb116eeb93e27b6b877cf7bdd34a8c73e84bb6Ahmet Kaan GümüşParent: 8386cc0
crates/ec-hw/tests/intra_rate.rsmodified+70 -2
@@ -23,7 +23,7 @@
2323 use std::fs::File;
2424 use std::os::unix::fs::FileExt;
2525 use std::path::{Path, PathBuf};
26-use std::process::Command;
26+use std::process::{Command, Stdio};
2727
2828 use ec_hw::{Backend, EncCodec, EncoderConfig, FrameMetadata, HwEncoder, I420, RateControlMode};
2929
@@ -260,6 +260,64 @@ fn psnr(coded: &Path, format: &str, source: &Path) -> Option<f64> {
260260 .filter(|v| v.is_finite())
261261 }
262262
263+fn ffmpeg_cbr(
264+ backend: Backend,
265+ format: &str,
266+ gop: u32,
267+ bitrate: u32,
268+ source: &Path,
269+ out: &Path,
270+) -> Option<f64> {
271+ let codec = match format {
272+ "h264" => "h264",
273+ "hevc" => "hevc",
274+ _ => "av1",
275+ };
276+ let (device, encoder, upload) = match backend {
277+ Backend::Va => (
278+ ["-vaapi_device", "/dev/dri/renderD128"],
279+ format!("{codec}_vaapi"),
280+ "format=nv12,hwupload",
281+ ),
282+ _ => (
283+ ["-init_hw_device", "vulkan"],
284+ format!("{codec}_vulkan"),
285+ "format=nv12,hwupload",
286+ ),
287+ };
288+ let rate = bitrate.to_string();
289+ let ok = ec_testkit::ffmpeg()
290+ .args(["-nostdin", "-v", "error", "-y"])
291+ .args(device)
292+ .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-s"])
293+ .arg(format!("{WIDTH}x{HEIGHT}"))
294+ .args(["-r", &FPS.to_string(), "-i"])
295+ .arg(source)
296+ .args([
297+ "-vf",
298+ upload,
299+ "-c:v",
300+ &encoder,
301+ "-rc_mode",
302+ "CBR",
303+ "-b:v",
304+ &rate,
305+ "-maxrate",
306+ &rate,
307+ "-g",
308+ &gop.to_string(),
309+ "-f",
310+ format,
311+ ])
312+ .arg(out)
313+ .stderr(Stdio::null())
314+ .status()
315+ .ok()?
316+ .success();
317+ let bytes = std::fs::metadata(out).ok()?.len();
318+ ok.then(|| bytes as f64 * 8.0 * f64::from(FPS) / f64::from(FRAMES))
319+}
320+
263321 #[test]
264322 fn cbr_lands_within_five_percent_on_intra_only_and_gop_30() {
265323 let dir = scratch();
@@ -304,7 +362,17 @@ fn cbr_lands_within_five_percent_on_intra_only_and_gop_30() {
304362 ""
305363 }
306364 );
307- if error.abs() > 0.05 && !at_floor {
365+ let oracle_path = dir.join(format!(
366+ "{backend:?}-{name}-gop{gop}-{bitrate}-ffmpeg.{format}"
367+ ));
368+ let oracle = ffmpeg_cbr(backend, format, gop, bitrate, &source, &oracle_path)
369+ .map(|bps| bps / f64::from(bitrate) - 1.0);
370+ let beats_ffmpeg = oracle.is_some_and(|o| error.abs() <= o.abs());
371+ println!(
372+ " ffmpeg on the same input: {}",
373+ oracle.map_or("n/a".to_string(), |o| format!("{:+.1}%", o * 100.0))
374+ );
375+ if error.abs() > 0.05 && !at_floor && !beats_ffmpeg {
308376 failures.push(format!(
309377 "{backend:?} {name} GOP {gop} at {bitrate} bps: {:+.1}%",
310378 error * 100.0