Merge branch 'lane-h265-rdo': five intra candidates reach the rate-distortion trial
Browse files at this commit2 changed files +30 -5
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 top | 76 | /// 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 a | 97 | /// 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 8x8 | 98 | /// *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 can | 16 | /// 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 ladder | 20 | /// 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 through | 21 | /// 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 a | 22 | /// 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 of | 24 | /// 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 after | 25 | /// 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 YUV | 27 | +/// • 3840x1608 film: -0.685 dB luma / -0.703 dB YUV |
| 28 | -/// • 1138x640 web clip: -0.603 dB luma / -0.632 dB YUV | 28 | +/// • 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 guards | 31 | /// 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 forced | 38 | /// 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 from | 39 | /// 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 of | 43 | /// A synthetic source with real structure: smooth gradients, a band of |
| 42 | /// sinusoidal texture and a translating box, so prediction matters — the half | 44 | /// 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 { |