forge
Explore
Log in

Don't you dare go Hollow

Give five intra candidates the rate-distortion trial

Browse files at this commit

b24f633ab66a169b1c2d6f31b5f0f8d66c461785Ahmet Kaan GümüşParent: ccc4650
  • perf
    • give five intra candidates the rate-distortion trial
Show full message
perf(h265): give five intra candidates the rate-distortion trial

The luma mode search screened 35 intra modes with SATD and handed only two
survivors to the full rate-distortion trial. That count was never measured;
it was the number the search was written with.

Swept against x265 at matched features on four real clips (BD-PSNR luma /
all-plane, 24 pictures after 1500, ladders auto-aligned, 0% extrapolation):

| k | 4K film | 1138x640 web | 1440p screen capture | 1080p phone |
|---|---------|--------------|----------------------|-------------|
| 1 | -0.840 / -0.815 | -0.728 / -0.733 | | |
| 2 | -0.731 / -0.730 | -0.603 / -0.632 | -2.521 / -2.420 | -0.435 / -0.444 |
| 3 | -0.703 / -0.709 | -0.556 / -0.596 | -2.493 / -2.402 | -0.401 / -0.416 |
| 4 | -0.693 / -0.705 | -0.530 / -0.574 | | |
| 5 | -0.685 / -0.703 | -0.507 / -0.556 | -2.465 / -2.360 | -0.366 / -0.387 |
| 8 | -0.684 / -0.710 | -0.471 / -0.525 | -2.453 / -2.368 | -0.340 / -0.361 |

Every clip improves monotonically to five. Eight buys +0.001 dB on the film
clip and takes its all-plane figure backwards, for another 20% of wall time,
so the knee is where the default now sits: film 38s -> 49s for the whole
four-QP ladder, web clip 8s -> 11s.

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