diff --git a/crates/ec-h265/src/encoder.rs b/crates/ec-h265/src/encoder.rs index a7ac1251..f15fb466 100644 --- a/crates/ec-h265/src/encoder.rs +++ b/crates/ec-h265/src/encoder.rs @@ -75,6 +75,24 @@ pub struct EncoderConfig { pub ctb_size: usize, /// How many of the 35 intra modes get a full rate-distortion trial, on top /// of the most probable mode, which always gets one. + /// + /// Swept against x265 at matched features on four real clips (BD-PSNR + /// luma / all-plane, wall time for the whole four-QP ladder): + /// + /// | k | film 3840x1608 | web 1138x640 | screen 2560x1440 | phone 1080p | + /// |---|----------------|-------------------|------------------|-------------| + /// | 1 | -0.840 / -0.815 38s | -0.728 / -0.733 8s | | | + /// | 2 | -0.731 / -0.730 40s | -0.603 / -0.632 9s | -2.521 / -2.420 29s | -0.435 / -0.444 11s | + /// | 3 | -0.703 / -0.709 43s | -0.556 / -0.596 10s | -2.493 / -2.402 31s | -0.401 / -0.416 11s | + /// | 4 | -0.693 / -0.705 46s | -0.530 / -0.574 10s | | | + /// | 5 | -0.685 / -0.703 49s | -0.507 / -0.556 11s | -2.465 / -2.360 35s | -0.366 / -0.387 13s | + /// | 8 | -0.684 / -0.710 59s | -0.471 / -0.525 14s | -2.453 / -2.368 41s | -0.340 / -0.361 16s | + /// + /// Every clip improves monotonically up to 5, which is why 5 is the + /// default. Eight buys nothing on the film clip (+0.001 luma, and its + /// all-plane figure goes *backwards*) for another 20% of wall time, so the + /// knee is where the default sits. `EC_H265_RDO_CANDIDATES` in the gate + /// test re-runs the sweep. pub rdo_candidates: usize, /// Smallest coding unit the search will produce, 8 or 16. Sixteen is a /// *coarser* search that is not always faster: on real pictures the 8x8 @@ -106,7 +124,7 @@ impl EncoderConfig { rate_control: RateControl::ConstantQp(27), threads: 0, ctb_size: 32, - rdo_candidates: 2, + rdo_candidates: 5, min_cu_size: 8, video_signal_type: None, sample_aspect_ratio: None, diff --git a/crates/ec-h265/tests/encode.rs b/crates/ec-h265/tests/encode.rs index c00c16ea..5c7b0707 100644 --- a/crates/ec-h265/tests/encode.rs +++ b/crates/ec-h265/tests/encode.rs @@ -16,7 +16,7 @@ type Planes = (Vec, Vec, Vec); /// measured value with 0.15 dB of room for platform noise, so the advantage can /// shrink but not grow unnoticed; it is not a claim that the number is fine. /// -/// Measured +2.456 dB luma / +3.158 dB YUV on the recalibrated run (352x288, +/// Measured +2.507 dB luma / +3.238 dB YUV at `rdo_candidates: 5` (352x288, /// 24 pictures of `Clip::render_smooth`, x265 at QP 22/26/30/34, our ladder /// auto-shifted from a QP-26 probe to 16/20/24/28, both sides decoded through /// ffmpeg, union-range BD-PSNR, 0% extrapolation both sides). This is a @@ -24,8 +24,10 @@ type Planes = (Vec, Vec, Vec); /// encoder is no leaner than x265 at matched QP (the probe measures a shift of /// 0) and the aligned BD is negative. Real-clip numbers, 24 pictures after /// 1500, ladders auto-aligned to 22/26/30/34, 0% extrapolation both sides: -/// • 3840x1608 film: -0.731 dB luma / -0.730 dB YUV -/// • 1138x640 web clip: -0.603 dB luma / -0.632 dB YUV +/// • 3840x1608 film: -0.685 dB luma / -0.703 dB YUV +/// • 1138x640 web clip: -0.507 dB luma / -0.556 dB YUV +/// • 2560x1440 screen capture: -2.465 dB luma / -2.360 dB YUV +/// • 1080p phone clip: -0.366 dB luma / -0.387 dB YUV /// Those two are the real gap to close; the synthetic number only guards /// against regression on a clip whose content is pinned. /// @@ -36,7 +38,7 @@ type Planes = (Vec, Vec, Vec); /// all-intra rate-quality slope is genuine content behaviour (x264 forced /// all-intra shows the same shape); the fix is to auto-align the ladders from /// a probe encode, not to change x265's rate control. -const BD_PSNR_VS_X265_FLOOR: f64 = 2.306; +const BD_PSNR_VS_X265_FLOOR: f64 = 2.357; /// A synthetic source with real structure: smooth gradients, a band of /// sinusoidal texture and a translating box, so prediction matters — the half @@ -425,6 +427,11 @@ fn bd_psnr_vs_x265() { cfg.rate_control = RateControl::ConstantQp(qp); cfg.keep_recon = true; cfg.threads = 0; + // Ablation knob: how many SATD survivors reach the full rate-distortion + // trial in the luma mode search. The shipped default is 5. + if let Ok(k) = std::env::var("EC_H265_RDO_CANDIDATES") { + cfg.rdo_candidates = k.parse().expect("EC_H265_RDO_CANDIDATES must be a number"); + } let enc = Encoder::new(cfg).expect("encoder"); let (mut stream, mut sum_recon) = (Vec::new(), 0.0); for (y, u, v) in &sources {