forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 552edc4cede0dfd9bebbc4e344242802802d15ccFiltered to crates/ec-h264/src/enc/headers.rsClear filter

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-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): 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.