Commits
Commits on
15b6d35dc229131ec372f415ec43b8a3e5c6e1e52026-08-24
ec-h265: add bd_psnr_vs_x265 gate against x265Ahmet Kaan Gümüş · 15b6d35
ec-h265: add bd_psnr_vs_x265 gate against x265 BD-PSNR of this encoder against x265 at matched features (intra-only, no B frames, in-loop filters off, AQ/psy/RDOQ off, QP 22/26/30/34) on the synthetic 352x288 24-picture clip, both sides decoded through ffmpeg. Measured: BD-PSNR luma -38.258 dB, BD-PSNR-YUV -31.656 dB. Floor calibrated at measured - 0.15 = -38.41 dB. The gap is wide because this encoder spends 40-70% fewer bits than x265 at every QP, so its rate-quality curve sits below x265's and the union-range cubic integral extrapolates; the convention is documented in bd_psnr_delta.
perf(h264): search the diagonals tooAhmet Kaan Gümüş · cdfa038
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.
feat(h264): let the inter decision see chromaAhmet Kaan Gümüş · 5f9d4c9
feat(h264): let the inter decision see chroma Every decision in the P path was made on luma alone: the motion search, the partition shape, the skip flag. Chroma was then coded against whatever vector came out, having never been asked about. Add the two chroma planes to the cost of the candidates that survive to the shape decision -- one motion compensation and one SATD per candidate, which the search proper could not afford but a handful of finalists can. Weight swept at 0, 0.25, 0.5, 1 and 2 on two contents, read on BD-PSNR-YUV; half is the optimum. Worth 0.041 dB on the film clip and nothing on the screen capture, which is small enough to be the useful part of the result: our chroma trails by 0.5-0.9 dB per plane at every QP, and this rules out the vector as the reason. Weighting chroma higher does lift chroma PSNR, monotonically, and past a half it spends more bits than the chroma is worth.
test(h264): report chroma per plane, and stop dropping the first x264 paramAhmet Kaan Gümüş · 8adad23
test(h264): report chroma per plane, and stop dropping the first x264 param The gate compared two encoders on a pooled all-plane number without ever saying which plane either one was losing. Print U and V separately per QP for both sides; on the film clip they say our chroma trails x264 by 0.48-0.90 dB uniformly across QP while we spend more bits, which is a prediction deficit rather than a starved one. EC_H264_X264_PARAMS was spliced in with a colon of its own, so a value written with a leading colon produced "::subme=1" -- and ffmpeg drops the token that follows an empty one. The parameter silently did not apply and the sweep read as "this x264 feature is worth nothing". Trim the colons off the value instead. Corrected attribution of x264's lead on the film clip, as BD-PSNR-YUV: its RD mode decision is worth 0.739 dB, its trellis quantisation 0.206, and the two are additive -- with both stripped we lead by 0.278 dB.
feat(h264): measure all three planes, and a chroma coded_block_pattern testAhmet Kaan Gümüş · 49e08f5
feat(h264): measure all three planes, and a chroma coded_block_pattern test The rate-quality gate measured PSNR on the luma plane alone, so any decision that could trade chroma bits for luma bits read as a pure gain. It now also reports an all-plane PSNR, pooled by sample count the way x264 reports it -- luma 6, each chroma plane 1 for 4:2:0 -- as BD-PSNR-YUV beside the luma number. Chroma gets the group test luma already has: cbp_chroma is 0, 1 (DC) or 2 (DC and AC), so one surviving AC block takes the pattern to 2 and makes the other seven each spend a coded_block_flag saying they are empty. The eight AC blocks are pooled, coding them is compared against zeroing them all, and the pattern step is charged CBP_CHROMA_BIT. Swept at 0, 4, 8, 16, 32 and 64 bits the charge reads -0.688/-0.681/-0.659/ -0.653/-0.670/-0.742 dB all-plane BD on a 3840x1608 film clip and -0.537/ -0.527/-0.530/-0.517/-0.524/-0.522 on a 2560x1440 screen capture; both turn over at sixteen. Read on luma alone the same sweep climbs monotonically to +0.079 dB at 64, which is the encoder buying luma by throwing chroma away. On the all-plane number the gap to x264 is -0.65 dB on the film clip against -0.18 luma, and -0.52 against -0.23 on the screen capture: chroma is the larger half of what is left, and nothing in this lane had been able to see it.
feat(h264): decide the coded_block_pattern group by rate-distortionAhmet Kaan Gümüş · 835b128
feat(h264): decide the coded_block_pattern group by rate-distortion Our residual luma still ran 10 to 17 per cent over x264's at a PSNR above x264's: blocks coded that x264 declines to code. The per-block zero test decides one block at a time, so a block surviving alone in its 8x8 group drags a coded_block_pattern bit behind it uncounted. x264 settles that with `decimate`, a count of how tightly the levels cluster at the front of the scan. Ported exactly, its optimum runs monotonically opposite on the two real clips -- camera grain wants it off, screen capture wants it harder than x264 sets it -- so it is a heuristic standing in for a test the encoder can run. Run the test instead: code the group only when its blocks buy more squared error than their levels plus the pattern bit are worth. That test needs the rate to be right. On the per-block estimate it reproduced the same content split; against CABAC's own cost for the same levels -- already in the encoder for RDOQ, in 256ths of a bit -- screen capture develops an interior optimum it never had. Both lambda and the pattern charge are swept, tables in their doc comments. BD-PSNR against x264 at matched features, consecutive pictures, at the balanced preset: 3840x1608 film -0.329 -> -0.321 dB, 2560x1440 screen capture -0.310 -> -0.252 dB. The same test on the 8x8 transform path is worth nothing across its sweep and is not kept; the negative result is recorded where the constant lives. The transform_8x8 flag gate pins the delta between two arms and drops from 0.255 to 0.230 dB because the flag-off arm is the path that improved -- the absolute synthetic comparison against x264 moves from -4.060 to -3.969 dB -- so it is re-pinned with that written beside it.
feat(h264): search each inter partition against its own predictorAhmet Kaan Gümüş · 1db6da0
feat(h264): search each inter partition against its own predictor A split macroblock's partitions were all searched against the whole macroblock's motion predictor, so the mvd the search costed was not the mvd the stream would carry: 8.4.1.3 gives 16x8 and 8x16 partitions directional shortcuts and 8x8 sub-partitions the median of their own neighbourhood. Partitions whose real predictor sat close by looked expensive and the search declined them. Derive the predictor inside the search loop instead. The neighbourhood comes from the picture, then the entries falling inside this macroblock on already-chosen partitions are filled from the vectors this loop has picked -- what the encoder will do when it codes them. That predictor also seeds the search. Both shape-signalling charges are re-swept on the new path. The quarters' twelve bits survive; the halves' six do not, and become three, with the sweep tables in their doc comments. BD-PSNR against x264 at matched features, consecutive pictures, at the balanced preset: 3840x1608 film -0.377 -> -0.329 dB, 2560x1440 screen capture -0.353 -> -0.310 dB.
2026-08-23
feat(h264): code P_8x8, and count shapes as well as bitsAhmet Kaan Gümüş · 2b1c4a3
feat(h264): code P_8x8, and count shapes as well as bits The encoder had no partition smaller than 8x16. It now codes P_8x8 with four P_L0_8x8 sub-partitions, including the sub_mb_type writer both entropy coders were missing. The first measurement of it read flat, as had the split-gate sweep before it, and a shape histogram said why: the partition search runs only at Preset::Balanced, and the x264 comparison runs Preset::Fast by default, so 1,200,000 macroblocks were coded whole and nothing was ever split. Measured where the shapes are searched, P_8x8 is worth 0.005 dB BD-PSNR on the film clip and 0.016 on the screen capture, with the optimum at twelve bits of signalling on both. The bit-exactness sweeps ran the default preset too, so no sub_mb_type had ever faced another decoder: balanced_partitions_decode_bit_exactly encodes at Balanced under CABAC and CAVLC, requires ffmpeg to reproduce the reconstruction sample for sample, and requires every shape to appear. The decoder now reports MbShapes alongside BitAccount, which puts our partition mix next to x264's: we still split about half as often.
perf(h264): search every partition, and document the split gateAhmet Kaan Gümüş · 338bd3f
perf(h264): search every partition, and document the split gate The bit account points at the motion field, so the search's two stopping rules were measured rather than assumed. The early exit that accepted a seed costing under half a level a sample is monotonically harmful -- 0/0.25/0.5/1.0 read -0.586/-0.587/-0.593/-0.617 dB BD-PSNR against x264 on the film clip and -0.466/-0.470/-0.468/-0.476 on the screen capture -- and removing it does not move the suite's wall clock, so it is gone. The gate on searching the 16x8 and 8x16 halves reads identically at four settings on both clips: real content clears it everywhere. It stays as a guard for flat content and is documented as one.
feat(h264): count CABAC bits by syntax class in the decoderAhmet Kaan Gümüş · 0723a49
feat(h264): count CABAC bits by syntax class in the decoder The rate gate says how much we overspend against x264; it cannot say on what. BitAccount marks the arithmetic decoder's position before and after each syntax element and attributes the difference to one of eight classes, so any conforming stream -- ours or x264's -- is measured by one instrument. bit_account_vs_x264 encodes both, decodes both, prints the table. The answer is the same on all three sources: we spend fewer bits than x264 on skip, mb_type and mvd, and more on residual luma, cbp+qp and intra modes. x264 buys a cheaper residual by paying more for the motion field. That points the next lane at prediction, not at entropy coding.
h264: record the mode-decision lambda sweep, which changes nothingAhmet Kaan Gümüş · 6deb39c
h264: record the mode-decision lambda sweep, which changes nothing The RD multiplier ladder had never been swept as a scale. It is now, on both real clips at the settled quantisation constants, and it sits on the crossing: film wants 0.7 (0.022 dB), screen capture wants 1.0 and loses 0.055 for the same move. Nothing landed; the table is in the lane report so the constant is not swept a third time.
h264: price the 8x8 inter blocks on their own bins tooAhmet Kaan Gümüş · fad4297
h264: price the 8x8 inter blocks on their own bins too residual_block_8x8_cost costs the cat-5 bins the writer writes, and the 8x8 path quantises, searches and zero-tests through it the way the 4x4 luma path does. quant_8x8 grew the same offset-naming sibling the 4x4 quantiser has, so the search picks the rounding that feeds it. Swept again rather than inherited: 8x8 answers like 4x4 luma, not like chroma, and keeps round-to-nearest. Measured as BD-PSNR of the opt-in transform_8x8 flag against flag-off, which is what isolates this path: film +0.535 -> +0.619, screen capture +0.042 -> +0.067. No default stream byte moves -- the flag is still off by default.
h264: price inter chroma AC levels the same wayAhmet Kaan Gümüş · e21a764
h264: price inter chroma AC levels the same way The RDOQ decision built for inter luma now also runs on the chroma AC blocks: rdoq_4x4 takes the block category and the DC-skipping flag, and block_ssd reconstructs through the AC-only unzigzag and dequant when it is set. The rounding that feeds the search had to be swept again rather than inherited. Luma wanted the wider 1/2 rounding once a search could take levels back down; chroma is monotonically worse for every widening and keeps the 1/6 inter dead zone it already had, taking only the pruning half. BD-PSNR against x264 on two real clips: film -0.628 -> -0.593, screen capture -0.471 -> -0.468; the synthetic gate is unchanged at -4.073 because its chroma planes are flat.
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.