forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 47083d34ae11b74b563f2816b1f73611a65a122e

2026-08-23

h264: choose inter luma levels against the CABAC coder's own priceAhmet Kaan Gümüş · 47083d3
h264: choose inter luma levels against the CABAC coder's own price

Rate-distortion quantisation for inter luma 4x4: each level is offered the
cheaper magnitudes below it, and takes one when the squared error it gives up
costs less than the bits it saves.

The rate is exact. `CabacEnc::residual_block_cost` runs the same bins
`residual_block` writes -- one body behind a `BinSink` the writer and the
price share -- against a copy of the context state, charging each bin -log2(p)
for its state and moving the state as the coder would. Over 400 random blocks
it predicts 2649288/256 bits where the coder then spends 2650112/256, an error
of 0.03%, which is asserted rather than assumed: a wrong price is invisible in
the stream and shows up only as lost dB.

An exact rate on its own was worth almost nothing (film -0.728 -> -0.732,
screen capture -0.500 -> -0.449). The half that pays is the dead zone: a search
that can only walk levels down cannot see a level the quantiser's 1/6 dead
zone already threw away, so it was choosing among the survivors of the decision
it was meant to replace. Quantising the searched path at 1/2 and letting the
search take the levels back down is worth 0.102 dB on the film clip and 0.301
on the synthetic gate. Deciding the whole-block zero on exact bits too adds
0.142 dB there.

BD-PSNR against x264 at matched features: film 3840x1608 -0.728 -> -0.628,
screen capture 2560x1440 -0.500 -> -0.471, synthetic -4.523 -> -4.073, the
floor moved to -4.15. Bounding the search to levels of 2 or less keeps it free
(synthetic run 1.08 s before, 1.09 s after; unbounded it was 3.53 s).

Intra stays out: its reconstruction is what the next block in the macroblock
predicts from. Inter chroma AC and the 8x8 path are not covered yet.
h264: withdraw the propagation explanation from the RD quantisation noteAhmet Kaan Gümüş · c844bb5
h264: withdraw the propagation explanation from the RD quantisation note

The addendum blamed the superset-measures-worse result on a reference
picture's quality being worth more than the local metric can see. x264
reports mbtree=0 rc=cqp in the streams this test compares against, so it
takes its 0.2 dB with no propagation term either, and the explanation does
not hold. The measurement stands; the cause is named as unsettled, with the
two remaining suspects and the experiment that separates them.
h264: record what coefficient-level RD quantisation measuredAhmet Kaan Gümüş · cf13a82
h264: record what coefficient-level RD quantisation measured

x264's trellis is worth 0.193 dB on the film clip and 0.208 on the screen
capture, re-measured against `trellis=0` now that the mode decision has
changed. A coefficient-level walk-back, with a scan-position-aware bit
estimate and the finished macroblocks picked on exact coded bits, buys
about 0.02 of that, so it is not landed: it doubles the inter coding work
for a fiftieth of the distance.

Two results worth keeping. A superset of candidates chosen on exact local
cost measured 0.05 dB worse than a pair of them, which is local
rate-distortion being myopic about a reference picture the next nine
predict from. And the generator walks levels on an estimate rather than
against the CABAC context that will actually code them, which is where
x264's version gets its order of magnitude.
h264: decide intra against inter on real coded costAhmet Kaan Gümüş · dbbd3cc
h264: decide intra against inter on real coded cost

The comparison was a prediction-domain SATD, discounted by a fixed 3/4 for
the Intra_4x4 that usually follows, against a coded inter cost, with the
intra side's signalling paid for by a guessed twelve bits. Both branches
are now coded for real and the one with the smaller squared error plus
lambda times its actual bits is kept -- the decision x264 makes from subme
6 up, and the mode half of the 0.83 dB the ablation in the lane report put
behind its refinement.

BD-PSNR against x264 at GOP 10 over QP 22/26/30/34: the film clip goes
-1.043 to -0.728, the screen capture -1.064 to -0.500, and the bit premium
falls with the distance rather than being traded for it (the screen capture
spends +17.2% over x264 at QP 22 where it spent +34.4%). The synthetic clip
loses 0.074 dB; it prefers a heavier rate term in that decision, which the
two real clips do not, so the standard multiplier goes in unscaled and its
floor moves -4.5 to -4.6.

Each P macroblock is coded twice and the loser's reconstruction and entropy
writer are thrown away: one measurement run went 28.8 s to 30.8 s wall.
Intra_4x4 in P pictures was re-swept under the new decision and stays on
everywhere; the two constants of the old decision are deleted rather than
re-swept, because nothing reads them any more.
docs(h264): name and sweep the search's motion-vector weightAhmet Kaan Gümüş · a5aa64e
docs(h264): name and sweep the search's motion-vector weight

The motion search halved a vector's signalling cost with a bare `/ 2.0`. Swept
on consecutive pictures it holds: 0.25/0.5/1.0/2.0 read -1.074/-1.043/-1.225/
-1.618 dB BD-PSNR against x264 on the film clip and -0.676/-0.661/-0.795/-1.201
on the screen capture, so a half is the flat part and charging the whole rate
is worse on both contents.
perf(h264): iterate sub-sample refinement to convergence at every presetAhmet Kaan Gümüş · f7bce7d
perf(h264): iterate sub-sample refinement to convergence at every preset

The refinement stopped after a single pass at Fast. Running it to convergence
is worth 0.111 dB BD-PSNR against x264 on the film clip and 0.035 on the screen
capture, for 2% of the comparison's wall clock; the synthetic floor tightens to
-4.5.

Attribution of what is left, measured by disabling x264's features one at a
time: its whole-sample search pattern is worth 0.04 dB, its rate-distortion
quantisation 0.20, and its sub-sample and mode refinement 0.83 -- so the
rate-distortion mode decision is where the remaining distance is.
docs(h264): re-measure the two parked decisions on the corrected samplerAhmet Kaan Gümüş · 463b2bc
docs(h264): re-measure the two parked decisions on the corrected sampler

`Preset::Balanced` and `transform_8x8` were both parked on numbers taken one
picture a second. On consecutive pictures Balanced wins on both contents
(-0.875 vs Fast's -1.154 on film, -0.506 vs -0.696 on screen capture) for 11%
more wall clock, and transform_8x8 reads +0.800 dB on film and +0.537 on screen
capture where it used to read 0.000 there.
fix(h264): measure the encoder on consecutive pictures, and pay for going intraAhmet Kaan Gümüş · ba061b6
fix(h264): measure the encoder on consecutive pictures, and pay for going intra

The real-clip comparison against x264 sampled one picture a second, so P
pictures had nothing to predict from and the P path was never really under
test: on a film clip our P slices ran 93.2% intra, 6.3% skip, 0.5% coded inter.
The sampler now takes consecutive pictures, with EC_H264_CLIP_STRIDE to restore
a wider spacing and EC_H264_CLIP_SKIP to pass over a film's titles first.

Corrected, the encoder read -1.521 dB BD-PSNR on film and -1.904 on screen
capture, spending 20-42% more bits than x264 with the premium growing with QP.
Two defects the old sampler had hidden:

- The intra side of the mode decision carried no rate term at all, while the
  inter side paid for its motion vector. Twelve bits for the macroblock type
  and the prediction modes is the overlap of the two contents' flat parts; a
  previous sweep of this same constant landed zero on the uncorrelated content.
- Sub-sample refinement chose on SAD, which reads interpolation's smoothing as
  a better match. It now costs candidates on SATD.

Together: film -1.521 -> -1.154 dB, screen capture -1.904 -> -0.696, synthetic
-5.718 -> -4.542, and the bit premium is flat in QP again (+14-18%) instead of
growing to +42%. The synthetic floor tightens to -4.6.

The other P-path constants swept under the old sampler were re-swept and all
held: Intra_4x4 in P pictures, the P_Skip rebate, and the Intra_4x4 discount.
mp3: gate VBR against the reference ladder, and split its frames tooAhmet Kaan Gümüş · 806ee38
mp3: gate VBR against the reference ladder, and split its frames too

VBR had no reference gate, which is why the demand-weighted frame split landed
in the CBR arm only. The gate encodes every rung of libmp3lame's VBR ladder on
each source and compares against the rung that actually spent what we spent --
nominal rates are no guide, since V6 is nominally 115 kbit/s and lands near 60
on speech.

Measured that way the shipped VBR lost almost everywhere: 11 of 14 rows behind
on correlation and up to 8 dB behind on the worst 20 ms window at the same
rate. The demand split takes that to 10 rows ahead, and recalibrating the
quality bar takes it to 13.

The recalibration is the second half of the split: reaching the same masking
bar for fewer bits has to be spent, not pocketed, because the quality knob
promises a mean rate. The bar now tightens by 1.6 - 12q decibels, fitted so
quality 0.3 lands at 162 kbit/s against its promised 163 and quality 0.6 at 232
against 230.

Floors are set from the measurement: correlation -0.0005, worst-window excess
3.5 dB, and 8% of the matched rung's rate, with top-rung rows exempt from the
rate check because the reference cannot spend more there.
mp3: split the frame budget by each channel's bit demandAhmet Kaan Gümüş · e90e593
mp3: split the frame budget by each channel's bit demand

CBR handed every granule-channel the same share of the frame, so the quiet
channel of a mid/side pair held bits it had no way to spend while the loud one
was starved. The quantiser codes |xr|^(3/4), so the sum of that over a
granule's lines is the shape of its demand; the frame is now split by it,
blended seven parts demand to three parts even.

The blend is where the two gate metrics disagree. Correlation keeps improving
to a pure demand split, but the worst 20 ms window turns around before it: at
full demand the loud granules take so much of the frame that a quiet one cannot
code its own transient, and one row falls 1.8 dB behind the reference. Seven
tenths takes nearly all the correlation and leaves every row's worst window
ahead.

All fourteen sweep rows now beat libmp3lame on both metrics. The correlation
floor becomes zero -- falling behind the reference at all is the regression --
and the worst-window excess tightens from 5.0 dB to 1.0.

The split is CBR only. VBR chooses its bitrate from the noise-to-mask ratio a
candidate reaches, and that mapping is calibrated to the even split: quality
0.5 settles at 154.6 kbit/s rather than 208 with the demand split in. Both want
to move together, against a VBR reference gate that does not exist yet.
mp3: code correlated stereo as mid/sideAhmet Kaan Gümüş · 21447bf
mp3: code correlated stereo as mid/side

The encoder declared joint stereo in every frame header and then wrote
mode_extension zero, which is plain left/right. The decoder had implemented
mid/side all along, so the two spoken-word sources in the library sweep were
coded twice over -- once per channel -- at half the bits each, and sat 12.6 dB
behind the reference in the worst 20 ms window.

A frame now takes mid/side when the difference of its channels is quieter than
their sum, which is every correlated mix and no opposed one. Both channels of a
frame take the same window, because adding a long block's lines to a short
block's describes two different time slices. A mid/side pair is held to
whichever channel masked less, since an error in the side channel lands in both
ears.

All fourteen sweep rows improve or hold. Five now beat the reference where
three did; the worst window on the speech rows closes to a tie at 192 kbit/s.
Both gate floors tighten onto the new worst rows: correlation to -0.0012, and
worst-window excess from 13.5 dB to 5.0 dB.
perf(mp3): stop amplifying at 85% of the frame budget, not 95%Ahmet Kaan Gümüş · 5912f29
perf(mp3): stop amplifying at 85% of the frame budget, not 95%

The worst-window metric from the last commit left a question: on the speech
sources the worst 20 ms barely improves when the bitrate rises by half, so
something other than the bit supply was capping it. The distortion loop has
three stop conditions and none of them had been swept.

Two are not live. Raising the round cap from 20 to 60 gives bit-identical
output, so the loop never reaches it, and amplifying one band per round instead
of three is a wash. The third is the budget break, and it is the whole story.
Stopping at 85% instead of 95% improves every one of the fourteen library rows
in correlation and none of them regresses in the worst window; reelm and hein
at 192 kbit/s gain 2.8 and 1.4 dB. The mean gap to the reference at 128 kbit/s
halves, from -0.00058 to -0.00033.

The other direction shows why. Letting the loop amplify to 100% of the budget
costs reelm 0.0048 correlation: past the budget an amplified band buys nothing
and the rate loop coarsens every other band to pay for it. Below 70% the
condition stops binding at all, since the first round already spends more.

Both gate floors tighten onto the new worst rows.
fix(mp3): wake the block switcher, and measure what it is forAhmet Kaan Gümüş · 4ca0311
fix(mp3): wake the block switcher, and measure what it is for

The switcher decided a granule was a transient when the next granule's total
energy grew eightfold. A granule is 13 ms, and music meets that about once a
minute: counting block types in our own coded streams found one short granule
in 9196, against libmp3lame's 88 over the same audio. It has been dead code
since it was written.

Sweeping the constant over 2 through 32 moved whole-file correlation by
0.00004, which is the second half of the finding: the crate's quality gate
cannot see pre-echo at all. A few milliseconds of noise smeared backwards
before an attack disappears into a minute of correlation, and a gate like that
would have accepted the switcher being deleted.

So the sweep now also reports the worst 20 ms error-to-signal ratio, for ours
and for the reference, skipping windows under -60 dBFS. Against that metric the
constant is not flat: at the shipped 8.0 one window of a real file carries more
error energy than signal (+1.1 dB), the curve is flat from 1.6 to 4, and the
cliff sits between 4 and 8. The shipped value was just past the edge of it.
4.0 lands, at the cheap end of the flat part.

The new gate's floor is set from the measurement and the measurement is
unflattering: we lead the reference in the worst window on all four music
sources and trail it on all three speech ones, worst by 14 dB. On those, the
worst window barely improves when the bitrate rises by half, so the limit is
the masking model rather than the bits. That is the next round.
test(mp3): measure the encoder against LAME on real sourcesAhmet Kaan Gümüş · e722375
test(mp3): measure the encoder against LAME on real sources

The crate's only quality gate compared correlations against a table frozen
from the encoder this one replaces, measured on synthetic fixtures. A frozen
number cannot notice the reference moving, and its thinnest row passed by
0.00014.

This adds a live one. `real_library_sweep_vs_lame` encodes the same sixty
seconds of the same file twice at matched constant bitrate -- once with
`Mp3Encoder`, once with libmp3lame -- decodes both through the same decoder,
aligns each against the samples that went in, and correlates. Matched CBR puts
the two sizes within 0.2% of each other, so what is left is quality.

Fourteen rows across seven sources land between -0.00137 and +0.00115, and the
floor is set just under the worst of them. The gap halves from 128 to 192
kbit/s on every source and is positive on the sparsest material, which points
at bit allocation on dense content rather than at the filterbank.
docs(lane): mark the screen-capture rows that are not comparableAhmet Kaan Gümüş · 5900f75
docs(lane): mark the screen-capture rows that are not comparable

Rounds 1-2 and rounds 3+ measured different captures, so only the film
clip and the fixture span the lane.
docs(lane): close the x264 rank-1 lane with its before-and-after tableAhmet Kaan Gümüş · 82c74f8
docs(lane): close the x264 rank-1 lane with its before-and-after table

Also records the rejected Intra_16x16 rate-distortion mode search and why
it does nothing where the Intra_4x4 one did.
docs(lane): record the class sweep of the remaining decision constantsAhmet Kaan Gümüş · d72bafc
docs(lane): record the class sweep of the remaining decision constants

Four more swept the same way; three are content-split and one is inert,
so none of them lands. Written down so the sweep is not repeated.
docs(lane): record the three swept decision constantsAhmet Kaan Gümüş · b939e05
docs(lane): record the three swept decision constants

Chroma cost, the intra penalty in P pictures and the P_Skip rebate, with
the per-QP rows showing the intra penalty was not a rate-quality trade,
and why the synthetic fixture now disagrees in sign.
perf(h264): size the P_Skip rebate to what skipping actually savesAhmet Kaan Gümüş · 1bfd070
perf(h264): size the P_Skip rebate to what skipping actually saves

The skip candidate was handed a four-bit rebate. Sweeping it against
x264 on three clips puts the flat part of the curve at 0-2 bits: on a
3840x1608 film clip at GOP 10, 0 and 2 read -0.113 and -0.110 dB where
4 reads -0.233 and 8 reads -0.708. The screen capture and the synthetic
clip move by 0.01 dB across the same range.

Two rather than zero because skipping does save signalling, and two is
the top of the flat region.
perf(h264): stop penalising intra macroblocks in P picturesAhmet Kaan Gümüş · 942a61a
perf(h264): stop penalising intra macroblocks in P pictures

The intra-versus-inter comparison added an eight-bit penalty to the
intra side, on the theory that an intra macroblock in a P picture also
costs the next picture's prediction quality. Measured, it costs the
opposite -- the intra macroblocks it suppressed were stopping drift from
accumulating across the GOP.

BD-PSNR against x264 -preset medium at GOP 10:

  3840x1608 film             -1.404 -> -0.233 dB
  2560x1440 screen capture   -0.033 -> +0.068 dB

and it is not a rate-quality trade: at every one of QP 22/26/30/34 the
unpenalised encoder is both smaller and 0.15-1.2 dB better on the film
clip. Penalties of 1, 2, 4 and 8 bits all measured worse and negative
ones measured the same, so zero is the flat part of the curve rather
than a tuned value.

The synthetic gate clip disagrees: it spends 5% more bits for the same
quality, because smooth ramps are what inter prediction is best at and
any intra macroblock there is waste, so the floor moves -5.40 -> -5.75.
The two contents disagreeing in sign is the signal that this decision
belongs on real coded cost rather than on a SATD comparison -- that is
the next slice, and the floor comment says so. Full ec-h264 suite green.
perf(h264): choose the chroma mode on SATD plus its signalling costAhmet Kaan Gümüş · cce1dad
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.
docs(lane): record the Intra_4x4 rate-distortion refinement roundAhmet Kaan Gümüş · 947e714
docs(lane): record the Intra_4x4 rate-distortion refinement round

Adds the cross-content table, the survivor-count saturation point, the
rate-term calibration that made the search work at all, and what the
next mode-decision slices are.
perf(h264): re-cost the Intra_4x4 mode survivors with real quantisationAhmet Kaan Gümüş · 8cda34e
perf(h264): re-cost the Intra_4x4 mode survivors with real quantisation

Ablating the reference showed x264's rate-distortion mode decision is
worth 0.80 dB intra of its lead, so the mode decision is where the
distance is. This does the first half of it: SATD still ranks the nine
Intra_4x4 modes, but the top three are re-costed by actually quantising
and reconstructing the block and charging reconstruction SSD plus coded
bits. A mode that predicts slightly worse can quantise to far fewer
levels, and SATD cannot see that.

Measured with bd_psnr_vs_x264 against x264 -preset medium:

  clip                        all-intra          GOP 10
  3840x1608 film              -0.749 -> -0.620   -1.557 -> -1.495
  2560x1440 screen capture    -0.225 -> -0.137   +0.173 -> +0.216

for 3-4% encode time. Three survivors is where it saturates: all nine
landed within 0.002 dB of three for 7% more time.

The rate term needs the same ZERO_BLOCK_LAMBDA correction the zero-block
test uses -- block_bits counts CAVLC-ish widths, and with the full term
the search loses 0.065 dB instead of gaining, and loses more the more
candidates it sees.

The synthetic clip pays 0.157 dB for this (-5.140 -> -5.297) and the floor
moves to -5.40. Its smooth ramps quantise unlike anything in a real frame;
all four measurements on real content gain. Full ec-h264 suite green.
test(h264): attribute x264's lead to its mode decision, not trellisAhmet Kaan Gümüş · b36a1af
test(h264): attribute x264's lead to its mode decision, not trellis

EC_H264_X264_PARAMS appends to the parameter list the gate hands libx264,
so a single reference feature can be switched off and the distance
re-measured. On the 3840x1608 clip:

  x264 configuration            GOP 10     all-intra
  -preset medium (the gate's)   -1.557 dB  -0.749 dB
  trellis=0                     -1.456 dB  -0.587 dB
  trellis=2                     -1.642 dB  -0.811 dB
  trellis=0:subme=1:me=dia      -0.873 dB  +0.216 dB

Trellis is worth 0.10 dB inter and 0.16 dB intra, so RDOQ is not the lever
it looked like. x264's rate-distortion mode decision is worth 0.80 dB intra
and a further 0.58 dB inter -- with it off we are ahead of x264 all-intra.

We pick macroblock and prediction modes on SATD plus an estimated rate;
x264 picks the survivors on true coded bits against reconstruction SSD.
That is where the remaining 1.4 dB is.
docs(h264): the dead zone is not where the distance to x264 isAhmet Kaan Gümüş · b25750f
docs(h264): the dead zone is not where the distance to x264 is

Swept both rounding-offset numerators against x264 with bd_psnr_vs_x264 on
a 3840x1608 clip, spelling them as sixty-fourths the way x264 spells
--deadzone-intra / --deadzone-inter. Two results, both recorded in
round_offset's doc comment and the lane report:

The intra offset is the one that matters, and ours is the better of the
two. x264's 11/64 reads -1.667 dB all-intra where ours (1/3, i.e. 21/64)
reads -0.745 dB, with the inter value making no difference to that.

The inter offset is inert across the useful range: 6/64, 16/64, 21/64 and
32/64 span -1.571 to -1.532 dB, a 0.04 dB spread, while the bit counts
move 0.8% -- so the path is reached and simply does not matter.

That leaves the remaining -1.557 dB (0.75 dB intra, 0.81 dB P pictures)
for trellis/RDOQ, P_8x8 sub-partitions and the intra mode decision.
perf(h264): try Intra_4x4 in P pictures at every presetAhmet Kaan Gümüş · f0a6733
perf(h264): try Intra_4x4 in P pictures at every preset

The BD-PSNR gate against x264 put us 2.992 dB behind on a 3840x1608 clip
from the library at Preset::Fast, and 1.587 dB behind at Preset::Balanced.
Ablating the four places the two presets differ shows the whole difference
sits in one of them: allowing Intra_4x4 in P pictures reads -1.557 dB on
its own, while a 48-sample search range (-3.039 dB), the half-macroblock
partitions (-3.009 dB) and the subpel refinement (-3.035 dB) each land
inside the noise of the -2.992 dB baseline.

So Intra_4x4 is now tried in P pictures at every preset. The cost is about
5% encode time (21.75 s against 20.67 s for the 24-picture measurement),
which is what a 1.4 dB rate-quality move is worth. Against x264 on that
clip we now spend 5-10% more bits instead of 19%, at 0.3-1.3 dB lower
PSNR instead of 1.0-1.7 dB.

The synthetic floor moves with the default: -5.202 dB to -5.140 dB, and
the constant is retightened to -5.25. No test in the repo pins encoder
bytes, so nothing else re-pins.
test(h264): gate on content prediction can win, not on noiseAhmet Kaan Gümüş · 5370748
test(h264): gate on content prediction can win, not on noise

The default clip for `bd_psnr_vs_x264` was `Clip::render`, whose
per-sample noise field is incompressible. On it x264 reads as 2x
cheaper mostly by throwing residual away -- at QP 30 it spends 224k
bits to our 672k and lands 0.5 dB *below* us -- so the BD-PSNR there
measured how willing each encoder is to abandon noise, not how well
either predicts. The tell: our `Preset::Balanced` scored worse
(-3.861 dB) than `Preset::Fast` (-2.640 dB) on that clip while scoring
much better on real content.

`Clip::render_smooth` replaces it for this test: gradients, a
sinusoidal texture band and a box translating by sub-sample amounts,
no noise. Its signature now matches the library clip's -- we spend
34-48% more bits and land 0.6-2.1 dB lower at the same quantiser --
and the floor moves to -5.40 dB from a -5.202 dB measurement. The
other tests keep `render`, which is the right source for them.

`EC_H264_PRESET_BALANCED` joins `EC_H264_GOP` as a diagnostic knob:
on the 3840x1608 library clip Balanced is -1.587 dB against Fast's
-2.992 dB for 40% more encode time, so over a dB of the P-picture
distance is search effort our default preset declines to spend.
fix(h264/test): match x264's quantiser, and split the gap intra vs interAhmet Kaan Gümüş · cd63f57
fix(h264/test): match x264's quantiser, and split the gap intra vs inter

The gate as committed asked x264 for a constant QP and did not get one:
x264's CQP mode scales the I-picture quantiser by `ipratio` (1.4 by
default), so its I pictures were coded finer than the QP under test.
That flattered x264 on the intra side and made the whole comparison a
different-quantiser comparison. `ipratio=1.0:pbratio=1.0:qcomp=1.0:
chroma-qp-offset=0` pins it; the synthetic BD-PSNR moves from -2.442 dB
to -2.640 dB, and the floor with it.

With the quantiser actually matched, `EC_H264_GOP` splits the distance.
On the 3840x1608 clip from the library:

    GOP 10 : -2.992 dB, ours +19% bits at 1.1-1.7 dB lower PSNR
    GOP  1 : -0.749 dB, ours +2-4% bits at 0.4-0.8 dB lower PSNR

So the intra path is close and roughly two thirds of the distance is in
P pictures: our inter path searches 16x16 only at `Preset::Fast`
(halves at Balanced, never 8x8 sub-partitions) with no rate-distortion
subpel refinement, and a worse prediction costs both bits and PSNR at
the same quantiser. That is the next lane's target, now measured
instead of assumed.

Ours is also read off ffmpeg's decode of our own stream rather than off
the encoder's reconstruction, matching how x264 is read; the two are
asserted equal within 0.05 dB.
test(h264): BD-PSNR gate against x264, the encoder's first referenceAhmet Kaan Gümüş · 5e93348
test(h264): BD-PSNR gate against x264, the encoder's first reference

The repo could measure the H.264 decoder against ffmpeg, the FLAC and
ALAC encoders against their references, and the audio encoders against
libopus/libvorbis, but the H.264 encoder only against itself: the
`transform_8x8` BD-PSNR test compares flag-on to flag-off, not us to
anyone. `bd_psnr_vs_x264` supplies the missing anchor.

Both curves are (bits, luma PSNR against the same source pictures) over
QP 22/26/30/34, and both are measured on decoder output rather than on
an encoder's own reconstruction, so the two halves are read the same
way; ours additionally asserts that its reconstruction and its decoded
stream agree within 0.05 dB, which turns a silent drift between the
encoder and the decoder into a failure here.

x264 is matched to what our encoder actually codes -- Main profile
(CABAC, no 8x8 transform), one reference, no B pictures, the same GOP
-- with adaptive quantisation, psy and scenecut off so both spend bits
by the same rule. Effort is each encoder's own default: our
`Preset::Fast` against x264's `-preset medium`.

First measurements: -2.442 dB on the synthetic clip (352x288, 24
pictures) and -2.961 dB on a 3840x1608 clip from the library, where we
spend 14-19% more bits and land 1-2 dB lower at the same QP. The
synthetic number becomes the floor at -2.60 dB so the distance can only
shrink; a clip named by EC_H264_CLIP prints but does not gate, its
content not being pinned. The test runs by default rather than behind
`#[ignore]`, because an invisible test rots.

The picture-extraction half of `real_clip_t8x8_bd_psnr` moves out to
`clip_sources` and is shared, unchanged in behaviour.
test(survey/r1): encoder-vs-reference gap rankingAhmet Kaan Gümüş · f8a771e
test(survey/r1): encoder-vs-reference gap ranking

Ranks every encoder in the tree by distance from the reference it replaces,
measured inline this batch rather than quoted from lane reports.

Worst first: ec-h264 has no encoder-vs-reference gate at all (x264 is invoked
in conformance.rs only to PRODUCE streams for decoder tests), so its rate-
quality distance is unmeasured while the transform_8x8 default-on decision
waits on it. Second, ec-vorbis trails libvorbis by 0.0027 corr at its worst
row where ec-opus now leads libopus on all 14 of its own -- and vorbis loses
exactly the rows where it spends fewer bits than the reference (nik@96
-1.60%, reelo@96 -1.43%) and wins the ones where it spends more (reelm +2.74%,
hein +2.05%), which is a steady under-spend, not a transient.

Below those: ec-mp3's VBR row passes its bar by 0.00014, the thinnest margin
in the repo; ec-image is -0.03 dB on WebP vs the incumbent; ec-aac, ec-flac
and ec-alac are at or ahead of their references (flac encodes 3.9% smaller
than ffmpeg, alac is bit-exact on 8/8).

Every default suite is green with no unexplained skips. The report lists what
could not run and why -- the env-gated SBR anchors (both run by hand for this
survey), the EC_H264_CLIP-gated BD-PSNR test, and the ~12-minute opus gate
whose numbers are the re-measurement from 41cf1d1.
test(aac/sbr): noise-fraction anchor summed core bands into a "whole-HF" ratioAhmet Kaan Gümüş · dccdbb8
test(aac/sbr): noise-fraction anchor summed core bands into a "whole-HF" ratio

`sbr_actual_noise_fraction` is env-gated (it sets process env vars mid-run,
which is unsound alongside parallel tests), so no default run executes it.
Run by hand it FAILED: "whole-HF realized noise fraction regressed to 0.0397
(round-44 fix floor is 0.17)".

Nothing regressed. Every band above the crossover realizes 0.15-0.27 of its
energy as injected noise, right where round-42/44 left it; the total was
diluted. `bin_level_conviction`'s rows start at `MIN_BAND` = 14 on ITS band
scale (rate/256, so ~2412 Hz), while this stream's crossover is QMF band 14
on the OTHER scale (rate/128, 4823 Hz) -- the same integer, two scales. The
dozen core-decoded rows that opens with carry an order of magnitude more
energy than the SBR-generated ones (6.4e4 vs ~5e3) and, by definition, zero
injected noise, so averaging them in dragged the ratio to 0.0397.

The total now starts at the stream's own crossover, taken from the lowest QMF
band the bookkeeping table holds (which IS `kx`), so a future QMF-mapping
change cannot silently invalidate it the way a constant did. It reads 0.1774
-- round-44 measured 0.1770 on this file -- and the assertion passes
untouched at its original 0.17 floor. Noise injection is also still doing
work: zeroing it costs 0.000847 of full-band correlation against the
reference.

Both anchors' SKIP lines now print the exact command that runs them, since
being invisible to default runs is what let a stale instrument sit unread.

`sbr_instrument_anchor_controls` was run too, and passes: ours-vs-ours 1.0000,
reference-vs-remux 1.0000, reference vs itself at a 64-sample offset 0.9317
mean / 0.3323 min (the coherence floor the instrument itself imposes).

Suite: 16 passed, 0 failed (54.1s).
test(aac/sbr): stride-1 lag search; the 0.40 core-only row was the instrumentAhmet Kaan Gümüş · 4aa4b5f
test(aac/sbr): stride-1 lag search; the 0.40 core-only row was the instrument

`core_only_matches_reference` printed `ch0: lag 1015, corr 0.402349` for
reeln in an otherwise green suite. The core is fine: the asserted
reference gate scores that file's below-5kHz band 0.999988, and
`full_chain_low_band_matches_own_core` scores this very core-only PCM 0.998
against our own full chain. A stride-1 sweep of the lag range shows the pair
correlating 0.999845 at lag 481 -- ffmpeg's resampler delay, the same lag FMJ
reads.

The search was missing it. Both `best_lag_correlation_ex` and
`robust_lag_topk` stepped their coarse pass by `SEARCH_STRIDE` (11) and then
refined around the best (or top-K) coarse scorer. A correlation peak between
two decodes of the same audio is often one sample wide -- here 0.9998 at 481,
0.94 at 479 -- so no grid point (the grid is 4 mod 11; 481 is 8 mod 11) saw
anything but the noise floor, and the refinement was pointed by a ranking of
noise. FMJ, same instrument and same true lag, happened to land a noise-ranked
candidate inside its refine window and read correctly, so the failure was
luck-dependent rather than file-dependent.

Both coarse passes now step by 1 (~33M multiply-adds at the narrow bound,
cheaper than the top-K refinement it replaces), and the diagnostic
low-passes both sides at 0.9 * crossover first, since only the reference
side -- ffmpeg's full SBR reconstruction resampled down to the core rate --
can hold anything above the crossover at all.

Class sweep: the sibling copies in ec-aac/obs_real_content.rs,
ec-matroska/matroska.rs and ec-ac3/encode_matrix.rs were already stride-1;
sbr_real_library.rs held the only strided searches in the tree.

Suite: 16 passed, 0 failed (53.4s). Every printed row is unchanged or
better; the four core-only rows now read 0.999779-0.999999.
Merge branch 'lane-opus-reell3': libopus importance[] for the tf ViterbiAhmet Kaan Gümüş · e9d01ed
Merge branch 'lane-opus-reell3': libopus importance[] for the tf Viterbi

The lane's premise (a startup pre-echo behind reell@96's err_ratio 4.499) was
wrong; lanes/opus-reell-r3.report.md records the measurement that refutes it.
What ships is the faithfulness fix the investigation surfaced: the tf Viterbi
now gets dynalloc_analysis's importance[] instead of a flat 13.
feat(opus): tf Viterbi gets libopus importance[] from dynalloc_analysisAhmet Kaan Gümüş · 95bb40e
feat(opus): tf Viterbi gets libopus importance[] from dynalloc_analysis

tf_analysis() was called with importance[i] = 13 for every band, a stand-in
constant. libopus derives it in dynalloc_analysis (celt_encoder.c:1176-1189)
as floor(.5 + 13*exp2(min(follower[i], 4))), with a flat 13 only on the
early-return path, and calls dynalloc_analysis before the tf decision. Both
now match: the call moved ahead of tf_res (it reads only band_log_e, so the
move is state-safe) and it fills importance[].

Metric-neutral on the 14-row library gate (corr moves <= 0.0001, err_ratio
unchanged, RATE/DROPOUT green); it ships as reference faithfulness.

Also corrects the module doc, which still described TF_ANALYSIS as false, and
records in lanes/opus-reell-r3.report.md that the reell@96 err_ratio premise was
wrong: our decode before the first attack is quieter than the reference by
orders of magnitude, not pre-echoing.
docs(opus): err_map header names its own source tagAhmet Kaan Gümüş · b53cc33
docs(opus): err_map header names its own source tag

The map test was generalised to any gate source (EC_ERRMAP_SRC/_KBPS/_TAG)
but still printed a hardcoded "her@" header, so a reell or reelo map claimed to
be her's. Header now uses the tag; module doc updated to match.
test(opus-reell/r3): error map generalised to any gate sourceAhmet Kaan Gümüş · 19ef3ae
test(opus-reell/r3): error map generalised to any gate source

her_err_map_96k -> err_map_vs_libopus; EC_ERRMAP_SRC / EC_ERRMAP_KBPS /
EC_ERRMAP_TAG select source, rate and output file, her@96 defaults kept.
docs(opus-her/r1): premise superseded by lane-opus-64; residual namedAhmet Kaan Gümüş · 9b54a5f
docs(opus-her/r1): premise superseded by lane-opus-64; residual named
refactor(h264rd/r3): extract decoder bS derivation; inter trial deblocking rejectedAhmet Kaan Gümüş · d3d7ad4
refactor(h264rd/r3): extract decoder bS derivation; inter trial deblocking rejected

bs_side/bs_between extracted from boundary_strength (8.7.2.1 in one
place); ssd_mb_deblocked parametrised by a bs closure, intra trials pass
intra_bs. Output byte-identical to r2.

The chartered change — derived per-edge bS in the inter cost4/cost8
trial — regressed the 720p clip in all three measured variants
(+0.818/+0.794/+0.821 vs +0.827 dB BD-PSNR; obs flat): the trial's
pre-filter neighbour aprons make weak inter strengths (bS 1/2) model
noise. Reverted per charter; numbers in lanes/h264rd-r3.report.md.
feat(h264rd/r2): deblock-aware intra 4x4 trial distortionAhmet Kaan Gümüş · bb59e0b
feat(h264rd/r2): deblock-aware intra 4x4 trial distortion

The transform_8x8 intra trial judged candidates by pre-filter SSD, which
prices the 4x4 candidate as if the bS-3 edges its extra transforms create
cost nothing under the loop filter every decoder runs. ssd_mb_deblocked
copies the candidate macroblock with 4-sample left/top aprons into a
scratch, filters it exactly as deblock_picture will - bS 4 on macroblock
edges when a neighbour exists, bS 3 on internal edges, the 4/12 luma
edges skipped for the 8x8 candidate as the decoder's internal() gate
does, verticals before horizontals, this qp, zero offsets - and SSDs that
instead. Chroma stays pre-filter (never 8x8-transformed, cannot separate
candidates); the flag-off path keeps ssd_luma + rough bits untouched.

Real clips, BD-PSNR flag-on vs flag-off q22/26/30/34:
  natural 720p film  +0.796 -> +0.827 dB
  obs 1440p capture  -0.007 -> -0.000 dB
test(h264rd/r2): real-clip BD-PSNR harness for transform_8x8Ahmet Kaan Gümüş · 04d77cb
test(h264rd/r2): real-clip BD-PSNR harness for transform_8x8

One #[ignore]d test in the existing encode.rs binary: EC_H264_CLIP names
a file, ec-mp4 + the crate decoder yield the first 30 pictures 1 s apart,
and a q22/26/30/34 sweep (gop 10, CABAC, full size) prints the flag-on vs
flag-off BD-PSNR and 8x8 MB share. Asserts nothing: the number gates the
lane, not the suite.

Baselines on the two lane clips (post-3165e8c pricing):
  natural 720p film  BD +0.796 dB, 8x8 share 13.5%
  obs 1440p capture  BD -0.007 dB, 8x8 share 1.9%
docs: opus-silkq r4 lane reportAhmet Kaan Gümüş · 8f45d03Browse files