From e6fcc5cc2788e495935cd800044f63dc8e2915b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 25 Aug 2026 14:04:47 +0300 Subject: [PATCH] feat(h264): 8x8 transform on by default x264 codes the 8x8 transform by default at every preset that reaches High profile, and measured on the library clips the flag is worth +0.716 dB BD-PSNR on a 3840x1608 film clip (18.1% of macroblocks take the 8x8 path) and +0.183 dB on a 2560x1440 screen capture (8.8%). With it on, the encoder's whole-picture comparison against x264 over q22/26/30/34 moves from -0.186 dB to +0.513 dB on the film clip and from -0.482 dB to -0.315 dB on the screen capture. Every default stream now carries profile_idc 100 and the High-profile SPS tail. `production_lambda_tracks_transform_mode` asked the default config for the 4x4 lambda, so it now clears the flag itself first. --- crates/ec-h264/src/enc/mod.rs | 13 +++++++------ crates/ec-h264/tests/encode.rs | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/ec-h264/src/enc/mod.rs b/crates/ec-h264/src/enc/mod.rs index 2aa0a949..27b19081 100644 --- a/crates/ec-h264/src/enc/mod.rs +++ b/crates/ec-h264/src/enc/mod.rs @@ -74,12 +74,12 @@ pub struct EncoderConfig { pub threads: usize, /// Quantiser for constant-QP mode (`bitrate` zero). pub qp: i32, - /// 8x8 transform (High profile). Off by default. + /// 8x8 transform (High profile). On by default, as it is in x264. /// - /// When enabled, eligible intra and inter luma macroblocks write - /// `transform_size_8x8_flag` and choose the 8x8 path with a squared-error - /// rate-distortion cost. Leaving it off preserves the Baseline/Main-profile - /// 4x4 path. + /// Eligible intra and inter luma macroblocks write `transform_size_8x8_flag` + /// and choose the 8x8 path with a squared-error rate-distortion cost. + /// Turning it off restricts the stream to the Baseline/Main-profile 4x4 + /// path, which costs 0.7 dB BD-PSNR on film and 0.2 dB on screen capture. pub transform_8x8: bool, #[cfg(feature = "rd-ablation")] rd_lambda_standard: bool, @@ -107,7 +107,7 @@ impl EncoderConfig { cabac: true, threads: 0, qp: 26, - transform_8x8: false, + transform_8x8: true, #[cfg(feature = "rd-ablation")] rd_lambda_standard: false, #[cfg(feature = "rd-ablation")] @@ -994,6 +994,7 @@ mod tests { #[test] fn production_lambda_tracks_transform_mode() { let mut cfg = EncoderConfig::new(640, 480); + cfg.transform_8x8 = false; assert_eq!( lambda_for(26, rd_lambda_standard(&cfg)), lambda_for(26, false) diff --git a/crates/ec-h264/tests/encode.rs b/crates/ec-h264/tests/encode.rs index a7f760c6..686a69d0 100644 --- a/crates/ec-h264/tests/encode.rs +++ b/crates/ec-h264/tests/encode.rs @@ -913,7 +913,7 @@ fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec