Iterate sub-sample refinement to convergence at every preset
Browse files at this commitf7bce7deb24bfae0122aed8bd9738ef4c653e276Parent: 463b2bc- perf
- iterate sub-sample refinement to convergence at every preset
3 changed files +29 -4
- crates/ec-h264/src/enc/mb.rs +5 -3
- crates/ec-h264/tests/encode.rs +1 -1
- lanes/h264x264-r2.report.md +23 -0
crates/ec-h264/src/enc/mb.rsmodified+5 -3
| @@ -642,6 +642,11 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Inter | ||
| 642 | 642 | // capture. The whole-sample winner is re-costed in the same domain |
| 643 | 643 | // first so the two halves of the search compare. |
| 644 | 644 | best.1 = cost_of(best.0, true); |
| 645 | + // Both sub-sample steps iterate to convergence at every preset. | |
| 646 | + // Stopping the refinement after one pass at Fast, which is what | |
| 647 | + // this used to do, costs 0.111 dB BD-PSNR on the film clip and | |
| 648 | + // 0.035 on the screen capture for 2% of the comparison's wall | |
| 649 | + // clock. | |
| 645 | 650 | for step in [2i16, 1] { |
| 646 | 651 | let mut improved = true; |
| 647 | 652 | while improved { |
| @@ -663,9 +668,6 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Inter | ||
| 663 | 668 | improved = true; |
| 664 | 669 | } |
| 665 | 670 | } |
| 666 | - if e.preset == Preset::Fast { | |
| 667 | - break; | |
| 668 | - } | |
| 669 | 671 | } |
| 670 | 672 | } |
| 671 | 673 | } |
crates/ec-h264/tests/encode.rsmodified+1 -1
| @@ -896,7 +896,7 @@ fn real_clip_t8x8_bd_psnr() { | ||
| 896 | 896 | /// signal that the decision belongs on real coded cost rather than on a SATD |
| 897 | 897 | /// comparison at all -- that is the next slice, not a reason to tune the |
| 898 | 898 | /// threshold back toward this clip. |
| 899 | -const BD_PSNR_VS_X264_FLOOR: f64 = -4.6; | |
| 899 | +const BD_PSNR_VS_X264_FLOOR: f64 = -4.5; | |
| 900 | 900 | |
| 901 | 901 | fn have_x264() -> bool { |
| 902 | 902 | std::process::Command::new("ffmpeg") |
lanes/h264x264-r2.report.mdmodified+23 -0
| @@ -117,3 +117,26 @@ screen capture**, at an 8x8 macroblock share of 17.3% and 14.2%. It is now a | ||
| 117 | 117 | win on both contents; what is still owed is the decision to flip the default, |
| 118 | 118 | because that changes every default stream byte and re-pins the byte-identity |
| 119 | 119 | tests. |
| 120 | + | |
| 121 | +## Addendum: where the rest of the gap is | |
| 122 | + | |
| 123 | +With x264's own features disabled one at a time, on consecutive pictures | |
| 124 | +(ours reads -1.154 film / -0.696 screen capture): | |
| 125 | + | |
| 126 | +| x264 running | film | screen | | |
| 127 | +| ---------------- | -----: | ------: | | |
| 128 | +| as configured | -1.154 | -0.696 | | |
| 129 | +| `trellis=0` | -0.959 | -0.594 | | |
| 130 | +| `me=dia` | -1.115 | -0.696 | | |
| 131 | +| `subme=4` | -0.905 | -0.579 | | |
| 132 | +| `subme=1` | -0.324 | -0.244 | | |
| 133 | + | |
| 134 | +The whole-sample search pattern is worth 0.04 dB and 0.00; rate-distortion | |
| 135 | +quantisation is worth 0.20 and 0.10; **sub-sample and mode refinement is worth | |
| 136 | +0.83 and 0.45** -- almost the entire remaining gap. x264's `subme` 6 and 7 are | |
| 137 | +its rate-distortion mode decision, which is the named next lane. | |
| 138 | + | |
| 139 | +Iterating our own sub-sample refinement to convergence at `Fast` (it stopped | |
| 140 | +after one pass) is the first 0.111 dB of that, for 2% of the comparison's wall | |
| 141 | +clock: film -1.154 -> -1.043, screen capture -0.696 -> -0.661, synthetic | |
| 142 | +-4.542 -> -4.449. |