forge
Explore
Log in

Don't you dare go Hollow

Search the diagonals too

Browse files at this commit

cdfa0380fe950f5fae1580ccfebcb0e5dca9a019Ahmet Kaan GümüşParent: 5f9d4c9
  • perf
    • search the diagonals too
Show full message
perf(h264): search the diagonals too

The whole-sample motion search stepped on a cross, so it could only walk along
an axis. A macroblock moving diagonally has to be reached in two steps through
a point that is worse than either -- and a step search stops at the first point
it cannot improve on, so it never took the first step. Step on a square
instead.

Worth 0.032 dB BD-PSNR-YUV on the film clip and 0.041 on the screen capture,
for twice the candidates in the stage that reads the reference in place and
never interpolates. The opening step size was swept alongside at 4, 8 and 16
whole samples and stays at four; wider is not a wider search, it only starts
the walk further from the seeds, which are already the answer most of the time.
crates/ec-h264/src/enc/mb.rsmodified+30 -1
@@ -601,6 +601,34 @@ fn intra_pre_cost(
601601 /// below a half and falls away above it.
602602 const MV_BITS_WEIGHT: f64 = 0.5;
603603
604+/// The offsets the whole-sample search steps through, in units of the current
605+/// step size.
606+///
607+/// A square, not a cross. The cross this used to be could only walk along an
608+/// axis, so a diagonally moving macroblock had to be reached in two steps
609+/// through a point that was worse than both -- and a step search stops at the
610+/// first point it cannot improve on. Adding the four diagonals is worth 0.032
611+/// dB BD-PSNR-YUV on the film clip and 0.041 on the screen capture for twice
612+/// the candidates in the whole-sample stage, which is the cheap stage: it reads
613+/// the reference in place and never interpolates.
614+///
615+/// The step the walk starts from was swept with it, at 4, 8 and 16 whole
616+/// samples: -0.580/-0.580/-0.593 dB on the film clip and -0.474/-0.493/-0.529
617+/// on the screen capture. Four is screen capture's optimum and inside film's
618+/// flat part -- a wider opening step is not a wider search here, it just lands
619+/// the walk further from the seeds, which are already the answer most of the
620+/// time.
621+const ME_PATTERN: [(i16, i16); 8] = [
622+ (1, 0),
623+ (-1, 0),
624+ (0, 1),
625+ (0, -1),
626+ (1, 1),
627+ (-1, -1),
628+ (1, -1),
629+ (-1, 1),
630+];
631+
604632 /// What the search charges P_8x8 for its own signalling, against the six bits
605633 /// a 16x8 or 8x16 is charged: an mb_type that is one bin longer plus four
606634 /// sub_mb_type bins, before the four predictors' own mvd.
@@ -871,7 +899,8 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Inter
871899 let mut improved = true;
872900 while improved {
873901 improved = false;
874- for (dx, dy) in [(step, 0), (-step, 0), (0, step), (0, -step)] {
902+ for (dx, dy) in ME_PATTERN {
903+ let (dx, dy) = (dx * step, dy * step);
875904 let cand = [best.0[0] + dx, best.0[1] + dy];
876905 if (cand[0] - mvp[0]).abs() > range * 4
877906 || (cand[1] - mvp[1]).abs() > range * 4