Commits
Commits on
cbbd6e2ef6acafb00aeb55e460423f024126f90fFiltered to crates/ec-h264/src/enc/quant.rsClear filter2026-08-23
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: 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.
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.
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): High-profile SPS/PPS tail + 8x8 forward transform/quant (E1+E2)Ahmet Kaan Gümüş · 250a6ac
feat(h264-enc): High-profile SPS/PPS tail + 8x8 forward transform/quant (E1+E2) SPS/PPS now write the High-profile 8x8-transform syntax (profile_idc 100, chroma/bit-depth/scaling-matrix fields, transform_8x8_mode_flag) behind a new EncoderConfig::transform_8x8 flag, and quant.rs gains forward_8x8/quant_8x8: an exact algebraic inverse of the decoder's idct8_1d (verified by rational matrix inversion, not a hand-tuned butterfly, since the small-integer transpose leaks ~15% between frequencies — too much for full-range residuals) paired with a plain-division dead-zone quantiser against the existing LevelScale8x8/dequant_8x8. transform_8x8 is NOT yet safe to turn on for a real encode: a conformant decoder unconditionally expects a transform_size_8x8_flag per eligible macroblock once the PPS advertises it (7.3.5), and enc::entropy/enc::mb don't write that bit yet (confirmed by a failing round trip, not left implicit). That emission, and the mode decision that actually picks 8x8 blocks, are later work.
2026-08-14
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.