Commits
2026-10-23
Restore edith_codecs after local data loss (2026-10-23)Ahmet Kaan Gümüş · b7434a2
Restore edith_codecs after local data loss (2026-10-23) On 2026-10-23 an automated agent ran `rm -rf $HOME` and deleted the local repository with all of its history. This commit restores the working tree from the newest surviving copy, the host-c server lane mirror. That mirror matches local main as of the testcut Phase 2 reports, including the tool cache, the nextest fast profile and changed-crates.sh. The history before this commit was not recovered.
2026-09-12
perf(h264): fuse the bi-predicted combining pass into motion compensationAhmet Kaan Gümüş · 57ad7eb
perf(h264): fuse the bi-predicted combining pass into motion compensation Default-weighted bi-prediction (8.4.2.3.1) is the rounded average of the two lists' clipped byte predictions, so list 0 now interpolates straight into the picture and list 1 averages on top of it (Put::Avg) instead of both landing in 256/64-byte temporaries, going through combine(), and being copied back per row. Weighted slices keep the temporary path. SliceCtx::no_weights() hoists the per-component weights_for lookup for streams that signal no weighted prediction at all. Byte-exact A/B vs d27a904d on five fixture classes (720p High CABAC+B, 720p CAVLC baseline, 1440p High no-B, 1080p Main, 4K Main): all display- order frame hashes identical. ec-h264 suite green (79 lib + 23 conformance + 12 encode + 1 decode-first).
2026-08-27
perf(h264): vectorize satd4 with the crate's wide-SIMD idiomAhmet Kaan Gümüş · 9d613d5
perf(h264): vectorize satd4 with the crate's wide-SIMD idiom Bit-identical: sha256 of all access units over the 640x360x30 bench clip matches the scalar build exactly (15b0075e...); full suite green.
2026-08-25
perf(h264): choose the Intra_8x8 luma mode by rate-distortionAhmet Kaan Gümüş · ccc4650
perf(h264): choose the Intra_8x8 luma mode by rate-distortion The Intra_8x8 chooser scored the nine prediction modes on SATD of the prediction residual plus a mode-bit term. That is a decision taken before the quantiser has a say: it never sees which mode's residual survives quantisation cheaply. Same class as the intra chroma chooser fixed in 98d01b7, and the last SATD-only intra site. Every allowed mode is now predicted, coded at the real QP and scored as SSD + lambda * bits, with the rate read from the CABAC coder's own 8x8 price (residual_block_8x8_cost — Luma8x8 has no coded_block_flag of its own, the CBP carries it, so the cbf-indexed cost path panics on it). BD-PSNR against x264 at matched features, 8x8 transform on, GOP 10, 24 consecutive pictures, luma / all-plane YUV: 3840x1608 film +0.475 / -0.068 -> +0.512 / -0.035 1138x640 web clip +0.040 / -0.031 -> +0.076 / +0.003 854x480 web clip +0.070 / +0.047 -> +0.132 / +0.108 2560x1440 screen -0.206 / -0.199 -> -0.215 / -0.207 Three clips of four gain on both metrics; the screen capture loses 0.008 dB. Encode time on the 854x480 clip goes from 12 s to 13 s. The path only runs when the 8x8 transform is enabled, which is still opt-in, so no default stream byte moves; the byte-identity conformance tests confirm it.
2026-08-24
perf(h264): choose the intra chroma mode by rate-distortionAhmet Kaan Gümüş · 495e450
perf(h264): choose the intra chroma mode by rate-distortion The chooser scored the four chroma prediction modes on SATD of the prediction plus the bits naming the mode, deciding before the quantiser had a say. Every available mode now goes through the real chroma coding path and is scored on reconstructed SSD plus what its levels and its name actually cost, which is the same measurement the rest of the macroblock decisions already make. Measured with bd_psnr_vs_x264 against x264 -preset medium, BD-PSNR-YUV, GOP 10, 24 consecutive pictures: 3840x1608 film -0.500 -> -0.443 dB, 2560x1440 screen capture -0.220 -> -0.146 dB, its second scene -0.571 -> -0.538 dB, a 1080p phone clip -1.122 -> -1.084 dB, a 720p web clip -0.606 -> -0.572 dB. Five clips of five improve; luma is unmoved (film -0.065 -> -0.070 dB) and encode time does not change measurably, since only intra macroblocks pay and only four chroma trials each.
perf(h264): give the chroma DC block a zero testAhmet Kaan Gümüş · 59070a1
perf(h264): give the chroma DC block a zero test Every other block in this encoder is asked whether coding it pays: luma 4x4 and 8x8, the chroma AC group, the macroblock's shape and skip flag. The chroma DC block was the exception — whatever the quantiser produced was coded, however little it bought. It gets the same test now. With only DC in a block the inverse transform gives every one of its sixteen samples the same (dc + 32) >> 6, so the squared error of zeroing the block is exact from the AC residual that is already reconstructed at that point: one sum per block, no second trial. BD-PSNR-YUV against x264 (GOP 10, QP 22/26/30/34, Preset::Balanced), test off -> on: film -0.504 -> -0.500, screen capture -0.227 -> -0.220, phone -0.300 -> -0.297, handheld -0.886 -> -0.884. The multiplier's ladder is in the comment on CHROMA_DC_LAMBDA; the peak is flat between 0.5 and 0.75 and turns sharply worse above 1.
perf(h264): choose chroma_qp_index_offset from the sourceAhmet Kaan Gümüş · eb83b6f
perf(h264): choose chroma_qp_index_offset from the source The offset was a hardcoded 0 in the PPS. Sweeping it showed the optimum is not a constant: a film clip is best at 0 and loses 0.16 dB at -2, while every screen capture and phone clip gains, one of them by 0.23 dB. What separates them is how textured the chroma planes are relative to luma — flat chroma is what wants the extra chroma bits, because its few edges are all the eye has to read there, and film's chroma carries as much detail as its luma, where the same bits buy more. So measure it: mean absolute sample gradient of the chroma planes over that of luma, taken on the first source picture, and code at -2 below half. The offset now reaches the PPS, the encoder's own chroma QP derivation and the deblocking parameters of every slice it writes, so reconstruction still matches a decode exactly. BD-PSNR-YUV against x264 (GOP 10, QP 22/26/30/34, Preset::Balanced) over nine clips, before -> after: -0.504 -> -0.504 (film, keeps 0), -0.406 -> -0.227, -0.495 -> -0.268, -0.601 -> -0.570, -0.639 -> -0.575, -0.931 -> -0.886, -0.510 -> -0.491, -0.352 -> -0.340, -0.376 -> -0.300. The rule reproduces each clip's own swept optimum.
perf(h264): decide the P shape and skip flag on coded costAhmet Kaan Gümüş · 6897ed7
perf(h264): decide the P shape and skip flag on coded cost
The motion search ranked its shapes by an SATD total plus a guessed
signalling charge, and the macroblock took that ranking as final. That
total is a prediction-domain estimate: it never sees the residual the
shape causes, so a split that looks cheaper to predict can cost more to
code than the 16x16 it displaced, and the encoder had no way to notice.
Intra against inter was already decided by coding both branches and
comparing squared error plus lambda times real bits. This extends the
same treatment to the inter side: choose_inter now returns every shape
it costed, most promising first, with P_Skip appended when the search
did not already prefer it, and the macroblock codes the list and keeps
the smallest coded cost.
BD-PSNR-YUV against x264 at GOP 10 over QP 22/26/30/34, Balanced:
film 3840x1608 screen 2560x1440
1 candidate -0.580 -0.474
2 -0.521 -0.459
3 -0.513 -0.447
5 -0.504 -0.406
monotone with no turnover, so the whole list is coded. Luma-only moves
-0.121 to -0.079 and -0.190 to -0.128. The film clip's comparison run
goes from 46s to 64s: a P macroblock is now coded up to five times and
every loser's reconstruction and entropy writer is thrown away, which
is why the list is Balanced-only and Fast still codes the SATD winner
alone.
This is the step the x264 feature ladder localised: subme 4 reads
-0.290 and subme 6 reads -0.581 on the film clip, the difference being
exactly that x264 stops estimating the mode decision and codes it.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.
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.
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: 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.
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.
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.
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.
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.
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
2026-08-21
2026-08-20
feat(h264-enc): honest 8x8 rate term, dead-zone 8x8 quantiser, 8x8 gain testAhmet Kaan Gümüş · b397db5
feat(h264-enc): honest 8x8 rate term, dead-zone 8x8 quantiser, 8x8 gain test The 8x8 quantiser now rounds with the same 1/3 (intra) / 1/6 (inter) dead zone as the 4x4 one, and the mode decision charges a level's position in a 64-coefficient significance map: without it Intra_8x8 was picked on 28 macroblocks that cost 44 real bits more each. The gain test codes curved shading, a 20-sample texture and glyph rows at qp 26: +0.30 dB at equal bits, 7.4% of macroblocks 8x8 (100 intra, 123 inter). The conformance gates assert 8x8 macroblocks of both kinds across their sweeps, and the VA-API decode runs with the flag on.
feat(h264-enc): Intra_8x8 prediction and the 8x8 transform for inter residuals, chosen on rate-distortion costAhmet Kaan Gümüş · 4e4673b
feat(h264-enc): Intra_8x8 prediction and the 8x8 transform for inter residuals, chosen on rate-distortion cost transform_size_8x8_flag now follows a real decision: Intra_8x8 is coded alongside Intra_4x4 and Intra_16x16 (decoder's filtered reference samples and neighbour-mode rule), P macroblocks try both transform sizes on the same prediction, and the residual writer takes the cat-5 / interleaved path. Encoder::transform_8x8_mbs() counts what was chosen; the reconstruction, ffmpeg and VA-API gates run with 8x8 macroblocks present.
feat(h264-enc): transform_size_8x8_flag emission + cat-5 / interleaved-CAVLC 8x8 residual writers (E3)Ahmet Kaan Gümüş · 655dfcc
feat(h264-enc): transform_size_8x8_flag emission + cat-5 / interleaved-CAVLC 8x8 residual writers (E3) Flag written (always 0 for now) wherever the decoder reads it under transform_8x8_mode_flag; CABAC residual_block_8x8 mirrors the decoder's cat-5 path (no coded_block_flag for 4:2:0); CAVLC sub_block_4x4 interleave helper. Round-trip unit tests through the decoder's own readers; encode integration tests gain transform_8x8=true variants.
2026-08-14
feat(h264): CABAC encoding, Main profile by defaultAhmet Kaan Gümüş · 466f297
feat(h264): CABAC encoding, Main profile by default The incumbent this encoder replaces writes High-profile CABAC; writing CAVLC against it costs roughly 12% of the bitrate at the same reconstruction, which no amount of mode-decision work makes back. That was the whole screen-capture quality gap. The encoder is the write side of the decoder's own CABAC: context initialisation, the ctxIdx offsets, the ctxIdxInc derivations and the block categories all come from crate::cabac, and the arithmetic encoder of 9.3.4 mirrors the decoder of 9.3.3 step for step. A single wrong context desynchronises the coder inside a macroblock, so the reconstruction test is what holds the two together. Slice data changes shape with the coder -- mb_skip_flag for mb_skip_run, end_of_slice_flag after every macroblock, cabac_alignment_one_bit before the first -- so the macroblock coder now writes syntax elements through one surface (enc::entropy) rather than bits, exactly as the decoder reads them through crate::entropy. Measured at matched bitrate, 1080p Fast: +1.1 dB on a screen capture and +0.25 dB on camera content. CAVLC stays available (EncoderConfig::cabac) and is covered by the same round-trip sweep.
feat(h264): software encoder, I and P pictures, CAVLC, slice-parallelAhmet Kaan Gümüş · 6d22228
feat(h264): software encoder, I and P pictures, CAVLC, slice-parallel The encoder shares the decoder's reconstruction rather than owning one: prediction (pred, inter), dequantisation and the inverse transforms (transform), the deblocking filter and the per-macroblock metadata are the decoder's own code and the decoder's own Picture. What is new here is the forward direction — forward transforms and quantisation (quant), CAVLC writing derived at compile time from the decoder's tables (vlc), parameter sets and slice headers (headers), mode decision and macroblock coding (mb), and rate control (rc). Scope: Baseline-profile syntax (8-bit 4:2:0 progressive, CAVLC, one reference, pic_order_cnt_type 2), intra 16x16 and 4x4 with chroma modes, P_Skip and P_L0_16x16 with a diamond search to quarter sample, and CBR rate control with a per-macroblock-row correction. Coding a picture as one slice per worker gives the parallelism inside the encoder: a slice is independent by definition, so every worker owns its picture buffer and its bitstream, and the bands are stitched and filtered once at the end. B pictures and CABAC are not coded yet; the bframes field is accepted and coded as zero rather than refused.