forge
Explore
Log in

Don't you dare go Hollow

Choose the chroma mode on SATD plus its signalling cost

Browse files at this commit

cce1dadd5a5bcd7c950ea7d8c9db4b83ba05ec3aAhmet Kaan GümüşParent: 947e714
  • perf
    • choose the chroma mode on SATD plus its signalling cost
Show full message
perf(h264): choose the chroma mode on SATD plus its signalling cost

The chroma prediction mode was picked on SAD with no rate term, while
everything else in the mode decision costs on SATD. The residual goes
through the transform, and naming the mode costs between one and five
bits (intra_chroma_pred_mode is ue(v)), so both belong in the cost.

Measured with bd_psnr_vs_x264 against x264 -preset medium:

  clip                        all-intra          GOP 10
  3840x1608 film              -0.620 -> -0.535   -1.495 -> -1.404
  2560x1440 screen capture    -0.231 -> -0.197   -0.062 -> -0.033
  352x288 synthetic ramp      -                  -5.297 -> -5.291

at no measurable encode time (20.4 s and 22.7 s on the film clip, both
before and after). SATD alone is about two thirds of the gain and the
rate term the rest. Full ec-h264 suite green.
crates/ec-h264/src/enc/mb.rsmodified+26 -3
@@ -987,7 +987,21 @@ fn code_chroma(
987 }987 }
988 }988 }
989 989
990-/// Pick the chroma prediction mode by SATD, leaving the winner in the planes.990+/// Pick the chroma prediction mode, leaving the winner in the planes.
991+///
992+/// SATD plus the mode's own signalling, not SAD: the transform is what the
993+/// residual actually goes through, and the four modes cost between one and five
994+/// bits to name. Measured with `bd_psnr_vs_x264` against x264 `-preset medium`,
995+/// SAD-with-no-rate-term -> this, at no measurable encode time:
996+///
997+/// | clip | all-intra | GOP 10 |
998+/// |---|---|---|
999+/// | 3840x1608 film | -0.620 -> -0.535 dB | -1.495 -> -1.404 dB |
1000+/// | 2560x1440 screen capture | -0.231 -> -0.197 dB | -0.062 -> -0.033 dB |
1001+/// | 352x288 synthetic ramp | - | -5.297 -> -5.291 dB |
1002+///
1003+/// SATD alone accounts for about two thirds of that and the rate term the rest
1004+/// (film all-intra: -0.620 -> -0.568 -> -0.535 dB).
991 fn choose_chroma_mode(1005 fn choose_chroma_mode(
992 pic: &mut Picture,1006 pic: &mut Picture,
993 e: &MbEnc<'_>,1007 e: &MbEnc<'_>,
@@ -1021,17 +1035,26 @@ fn choose_chroma_mode(
1021 origin,1035 origin,
1022 };1036 };
1023 pred_chroma_8x8(mode, &mut win, nbr.b, nbr.a);1037 pred_chroma_8x8(mode, &mut win, nbr.b, nbr.a);
1024- cost += sad(1038+ cost += satd_block(
1025 src,1039 src,
1026 e.src.c_stride,1040 e.src.c_stride,
1027 mb_x * 8,1041 mb_x * 8,
1028 mb_y * 8,1042 mb_y * 8,
1029- &plane.data[origin..],1043+ &plane.data,
1030 stride,1044 stride,
1045+ origin,
1031 8,1046 8,
1032 8,1047 8,
1033 );1048 );
1034 }1049 }
1050+ // What signalling the mode costs: intra_chroma_pred_mode is ue(v), so
1051+ // DC is one bit and the plane mode five.
1052+ let bits = match mode {
1053+ 0 => 1.0,
1054+ 3 => 5.0,
1055+ _ => 3.0,
1056+ };
1057+ cost += motion_rate(e, bits);
1035 if cost < best.0 {1058 if cost < best.0 {
1036 best = (cost, mode);1059 best = (cost, mode);
1037 }1060 }