Commits
Commits on
00c1b3ff2d80d84fef71bb6208110dedbbd95fc4Filtered to crates/ec-h264/src/enc/mod.rsClear filter2026-08-25
feat(h264): 8x8 transform on by defaultAhmet Kaan Gümüş · e6fcc5c
feat(h264): 8x8 transform on by default x264 codes the 8x8 transform by default at every preset that reaches High profile, and measured on the library clips the flag is worth +0.716 dB BD-PSNR on a 3840x1608 film clip (18.1% of macroblocks take the 8x8 path) and +0.183 dB on a 2560x1440 screen capture (8.8%). With it on, the encoder's whole-picture comparison against x264 over q22/26/30/34 moves from -0.186 dB to +0.513 dB on the film clip and from -0.482 dB to -0.315 dB on the screen capture. Every default stream now carries profile_idc 100 and the High-profile SPS tail. `production_lambda_tracks_transform_mode` asked the default config for the 4x4 lambda, so it now clears the flag itself first.
2026-08-24
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.
2026-08-21
2026-08-20
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.
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): 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.