forge
Explore
Log in

Don't you dare go Hollow

Try Intra_4x4 in P pictures at every preset

Browse files at this commit

f0a6733bb7622f9416fb8d25e5a46ccd9226faefAhmet Kaan GümüşParent: 5370748
  • perf
    • try Intra_4x4 in P pictures at every preset
Show full message
perf(h264): try Intra_4x4 in P pictures at every preset

The BD-PSNR gate against x264 put us 2.992 dB behind on a 3840x1608 clip
from the library at Preset::Fast, and 1.587 dB behind at Preset::Balanced.
Ablating the four places the two presets differ shows the whole difference
sits in one of them: allowing Intra_4x4 in P pictures reads -1.557 dB on
its own, while a 48-sample search range (-3.039 dB), the half-macroblock
partitions (-3.009 dB) and the subpel refinement (-3.035 dB) each land
inside the noise of the -2.992 dB baseline.

So Intra_4x4 is now tried in P pictures at every preset. The cost is about
5% encode time (21.75 s against 20.67 s for the 24-picture measurement),
which is what a 1.4 dB rate-quality move is worth. Against x264 on that
clip we now spend 5-10% more bits instead of 19%, at 0.3-1.3 dB lower
PSNR instead of 1.0-1.7 dB.

The synthetic floor moves with the default: -5.202 dB to -5.140 dB, and
the constant is retightened to -5.25. No test in the repo pins encoder
bytes, so nothing else re-pins.
crates/ec-h264/src/enc/mb.rsmodified+11 -3
@@ -50,10 +50,10 @@ use super::{
5050 /// the two edith actually picks between.
5151 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5252 pub enum Preset {
53- /// Diamond motion search, 16x16 partitions, intra 4x4 in I pictures only.
53+ /// Diamond motion search, 16x16 partitions.
5454 #[default]
5555 Fast,
56- /// Wider search with a hexagon refinement and intra 4x4 everywhere.
56+ /// Wider search with a hexagon refinement and half-macroblock partitions.
5757 Balanced,
5858 }
5959
@@ -434,7 +434,15 @@ fn intra_pre_cost(
434434 IntraCost {
435435 i16_mode: best.1,
436436 i16_cost: best.0,
437- allow_i4: e.slice_type == SliceType::I || e.preset == Preset::Balanced,
437+ // Intra_4x4 is tried in P pictures too, at every preset. Measured
438+ // against x264 on a 3840x1608 clip from the library (BD-PSNR over QP
439+ // 22/26/30/34, matched features): restricting it to I pictures cost
440+ // -2.992 dB against x264 where allowing it everywhere reads -1.557 dB,
441+ // for 5% more encode time. Nothing else in the Fast/Balanced split
442+ // came close -- a 48-sample search range read -3.039 dB and the
443+ // half-macroblock partitions -3.009 dB, both inside the noise of the
444+ // -2.992 dB baseline.
445+ allow_i4: true,
438446 }
439447 }
440448
crates/ec-h264/tests/encode.rsmodified+5 -3
@@ -863,12 +863,14 @@ fn real_clip_t8x8_bd_psnr() {
863863 // ---------------------------------------------------------------------------
864864
865865 /// Floor for [`bd_psnr_vs_x264`] on the synthetic clip. Our encoder measured
866-/// -5.202 dB against x264 there on 2026-08-23 (352x288, 24 pictures of
866+/// -5.140 dB against x264 there on 2026-08-23 (352x288, 24 pictures of
867867 /// `Clip::render_smooth`, both encoders at their own default effort: our
868868 /// `Preset::Fast`, x264's `-preset medium`). The floor is that number with
869869 /// room for platform noise, so the distance can shrink but not grow
870-/// unnoticed; it is not a claim that -5.2 dB is fine.
871-const BD_PSNR_VS_X264_FLOOR: f64 = -5.40;
870+/// unnoticed; it is not a claim that -5.1 dB is fine. On a 3840x1608 clip
871+/// from the library the same measurement reads -1.557 dB, so this synthetic
872+/// number is the pessimistic end of the range, not the typical one.
873+const BD_PSNR_VS_X264_FLOOR: f64 = -5.25;
872874
873875 fn have_x264() -> bool {
874876 std::process::Command::new("ffmpeg")