Try Intra_4x4 in P pictures at every preset
Browse files at this commitf0a6733bb7622f9416fb8d25e5a46ccd9226faefParent: 5370748- perf
- try Intra_4x4 in P pictures at every preset
2 changed files +16 -6
crates/ec-h264/src/enc/mb.rsmodified+11 -3
| @@ -50,10 +50,10 @@ use super::{ | |||
| 50 | /// the two edith actually picks between. | 50 | /// the two edith actually picks between. |
| 51 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] | 51 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 52 | pub enum Preset { | 52 | pub enum Preset { |
| 53 | - /// Diamond motion search, 16x16 partitions, intra 4x4 in I pictures only. | 53 | + /// Diamond motion search, 16x16 partitions. |
| 54 | #[default] | 54 | #[default] |
| 55 | Fast, | 55 | Fast, |
| 56 | - /// Wider search with a hexagon refinement and intra 4x4 everywhere. | 56 | + /// Wider search with a hexagon refinement and half-macroblock partitions. |
| 57 | Balanced, | 57 | Balanced, |
| 58 | } | 58 | } |
| 59 | 59 | ||
| @@ -434,7 +434,15 @@ fn intra_pre_cost( | |||
| 434 | IntraCost { | 434 | IntraCost { |
| 435 | i16_mode: best.1, | 435 | i16_mode: best.1, |
| 436 | i16_cost: best.0, | 436 | 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, | ||
| 438 | } | 446 | } |
| 439 | } | 447 | } |
| 440 | 448 | ||
crates/ec-h264/tests/encode.rsmodified+5 -3
| @@ -863,12 +863,14 @@ fn real_clip_t8x8_bd_psnr() { | |||
| 863 | // --------------------------------------------------------------------------- | 863 | // --------------------------------------------------------------------------- |
| 864 | 864 | ||
| 865 | /// Floor for [`bd_psnr_vs_x264`] on the synthetic clip. Our encoder measured | 865 | /// 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 |
| 867 | /// `Clip::render_smooth`, both encoders at their own default effort: our | 867 | /// `Clip::render_smooth`, both encoders at their own default effort: our |
| 868 | /// `Preset::Fast`, x264's `-preset medium`). The floor is that number with | 868 | /// `Preset::Fast`, x264's `-preset medium`). The floor is that number with |
| 869 | /// room for platform noise, so the distance can shrink but not grow | 869 | /// 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. | 870 | +/// unnoticed; it is not a claim that -5.1 dB is fine. On a 3840x1608 clip |
| 871 | -const BD_PSNR_VS_X264_FLOOR: f64 = -5.40; | 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; | ||
| 872 | 874 | ||
| 873 | fn have_x264() -> bool { | 875 | fn have_x264() -> bool { |
| 874 | std::process::Command::new("ffmpeg") | 876 | std::process::Command::new("ffmpeg") |