forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 8dbd683068d7f87f21dcc4ed1dfdca786d82c52bFiltered to crates/ec-av1/src/encode.rsClear filter

2026-08-26

feat(av1): inter encode loop — decoded-reference sequence codingAhmet Kaan Gümüş · 50130dc
feat(av1): inter encode loop — decoded-reference sequence coding

encode_sequence keys the first picture and codes every later one against the
previous frame's own decoded reconstruction (single LAST slot). Per-block RD
weighs the intra modes against NEARESTMV and NEWMV, mv bits priced through the
CDF intervals. Inter residuals are corner-cut to skip=true pending the tile
writer's is_inter coefficient desync fix; the ceiling and reinstatement point
are named at the corner-cut comment.
feat(av1): coefficient CDFs for all four q contextsAhmet Kaan Gümüş · 2edeb94
feat(av1): coefficient CDFs for all four q contexts

Q0/Q1/Q3 tables added alongside the existing Q2 (61..=120) family for
all 34 coefficient CDF groups, transcribed and verified against the
Q2 baseline. tile::q_ctx_of buckets base_q_idx into the four bands
(0..=20, 21..=60, 61..=120, 121..=255) and Cdfs::pick selects the
matching table, so the tile writer now accepts the full 0..=255 range
instead of refusing everything outside 61..=120.

Removed the three test assertions that pinned the old refusal
(a_picture_off_the_block_grid_is_refused, dc_levels_the_base_syntax_-
cannot_carry_are_refused, coefficients_the_writer_cannot_code_are_-
refused) and extended the ffmpeg roundtrip and quantizer-monotonicity
gates to exercise one q index from each context, including the three
context boundaries.
feat(av1): inter tile writer sb_coeff_inter_frame_tileAhmet Kaan Gümüş · 302d3c4
feat(av1): inter tile writer sb_coeff_inter_frame_tile

Flat 32x32-block-grid writer for inter frames: skip -> is_inter (ctx
from above/left skip+inter tracking) -> intra path (Y_MODE by size
group, not KF_Y_MODE) or inter path (single_ref chain, find_mv_stack,
read_inter_mode NEWMV/NEARESTMV, DRL idx 0 only, mv_joint + per
component symbols) -> existing coefficient path. Widens
SymbolDecoder::symbol to pub(crate) for cross-module roundtrip tests.

One-line encode.rs fix required for BlockCoeffs' two new fields
(skip, inter) via ..BlockCoeffs::default() at its one non-spread
construction site.

Corner-cuts (documented in tile.rs): whole-superblock frames only,
DRL always index 0, allow_high_precision_mv=0 assumed (validated,
not silently rounded), InterMode limited to NearestMv/NewMv.
feat(av1): write inter frame headers, referencing one reference slotAhmet Kaan Gümüş · d95e550
feat(av1): write inter frame headers, referencing one reference slot

Extends write_frame_header to shown inter frames: error_resilient_mode,
primary_ref_frame, refresh_frame_flags, the ref_order_hint loop (when
error-resilient), frame_refs_short_signaling (off) + ref_frame_idx[0..7],
allow_high_precision_mv, interpolation_filter (EIGHTTAP, non-switchable),
is_motion_mode_switchable, use_ref_frame_mvs, reference_select (forced off,
non-zero refused by name along with the skip mode and warped motion it
gates), and per-reference is_global (forced identity, non-identity global
motion refused by name). Adds inter_frame_headers() beside key_frame_headers,
reusing its sequence header verbatim and pointing every ref_frame_idx at the
slot holding the previous decoded frame.

New inline test parses a key + two inter frame header sequence back through
ec_av1_syntax::Av1Parser's own FrameState threading and checks every field
(after taking the reader's own derived fields — showable_frame, OrderHints,
RefFrameSignBias, header_bits — from the parse) plus written-vs-consumed bit
length, per frame.
feat(av1): 32x32 quadrants split into 16x16 blocks when RD says soAhmet Kaan Gümüş · 7d10ec2
feat(av1): 32x32 quadrants split into 16x16 blocks when RD says so

Each quadrant is now coded twice -- whole, and as four 16x16 sub-blocks --
and the cheaper of the two is kept, with the partition symbol's own rate in
both costs. The reconstruction is snapshotted and restored between trials so
prediction always reads the winner, and mode bookkeeping moved to the 16x16
grid the spec's mode context is defined on.

Measured over a three-point ladder against the whole-only encoder: -9.15%
BD-rate on 1080p film, -27.20% on screen capture, -9.05% on a phone clip,
-22.45% on the synthetic diagonal, and +0.00% on stripes, which never splits.

Mixing block sizes exposed a real conformance defect: the chroma txb_skip and
DC-sign contexts were read from a single neighbour cell, while the decoder
gathers over every 4x4 unit the block spans (spec 5.11.39, 8.3.2). Under a
uniform 32x32 encoder the one cell is the whole span, so the bug could not
show; with a 16x16 beside a 32x32 the arithmetic decoder desynchronised as
+-1 sample drift. Neighbours::around now gathers both edges. Two gates added:
a 16x16 inverse-transform comparison against ffmpeg, and a direct test that
the gathered read sees a cell the single-cell read misses.
feat(av1): the tile adapts its CDFs as it writesAhmet Kaan Gümüş · 8a54f53
feat(av1): the tile adapts its CDFs as it writes

AV1's symbol decoder updates every non-literal CDF it reads, so an encoder
that leaves `disable_cdf_update` off has to keep the same state and update it
in the same order. This adds that state and writes the key frame's tile
through it.

Tables the decoder keeps one copy of are one copy here too: a 64x64 luma
transform reads the 32x32 base-range rows, both luma sets share one DC sign
and one 1024-position end-of-block table, and both chroma sets share their own
sign table. The gathered partition CDF an edge superblock reads is built for
the read and thrown away, so nothing adapts there.

The coefficient rate term still prices against the defaults: the mode search
runs before the tile is written, so the adapted state does not exist yet.

BD-rate against the same encoder with adaptation off, over a three-point
ladder: -3.52% on a 1080p film frame, -5.63% on a screen capture, -11.25% on
the test card. The ffmpeg/dav1d roundtrips are the gate -- a decoder adapting
its own tables desyncs the moment the order or the sharing differs.

2026-08-25

feat(av1): the mode search prices its coefficients through the writer's CDFsAhmet Kaan Gümüş · 870ed18
feat(av1): the mode search prices its coefficients through the writer's CDFs

The mode search costed the mode symbol exactly and the levels with a
magnitude estimate. Now the levels go through write_coeffs on a throwaway
encoder, so a trial is ranked by the bits the tile writer will really spend
on it: end-of-block position, base levels, base range, signs and the Golomb
tail, under the block's own contexts.

The bit account prices the interval narrowing each symbol performs rather
than its table entry, because the coder's eight-bit range multiply and its
EC_MIN_PROB floor put the table entry 8% off the bytes actually written.

Worth -1.19% BD-rate on a 1080p film frame and -0.20% on a screen capture
against the estimate; LAMBDA_SCALE stays 0.1, re-swept.
feat(av1): the six directional intra modes, and a mode-rate termAhmet Kaan Gümüş · 223aa7c
feat(av1): the six directional intra modes, and a mode-rate term

Adds D45, D67, D113, D135, D157 and D203 per spec 7.11.2.4, with the
edge construction of 7.11.2.2 and the availability the decoder derives
from clear_block_decoded_flags: for the 32x32 quadrants of a superblock
the above row reaches past the superblock's right edge (sbWidth4 is
measured to the tile's end column) for all but the last quadrant, and
the left column continues below only for the first.

The mode search now also pays for naming a mode, scored through the tile
writer's own CDFs -- the KF_Y_MODE symbol under the neighbours' context,
the ANGLE_DELTA zero symbol, and the chroma mode symbol the luma mode
indexes. Without it a directional mode looked free and cost 1.1% rate on
a picture that did not want one. With it, and with LAMBDA_SCALE re-swept
to 0.1, the same picture costs 0.41% and the clips that do want a
direction gain up to 0.35%.

ffmpeg decodes all thirteen modes bit-exactly at 128x96 and 160x96.
feat(av1): seven intra modes, picked per block by rate-distortionAhmet Kaan Gümüş · 4331d17
feat(av1): seven intra modes, picked per block by rate-distortion

The predictors of spec 7.11.2 that read no further than the row above and the
column left of a block -- DC, V, H, SMOOTH, SMOOTH_V, SMOOTH_H and PAETH -- with
the edge construction that fills a missing side from the side that exists. Each
32x32 luma block now codes under all seven and keeps the one whose squared error
and estimated rate come out cheapest; chroma stays DC, which is the mode the tile
writer codes for it.

The weight on rate was swept over three real clips and two synthetic pictures at
six values; 0.05 step-squared per bit is the best point on every one. Against DC
alone it saves 11.5% of the rate on screen capture, 7.8% on the test card and
59.5% on a picture that runs one way. Against libaom the gap at matched size on a
film frame narrows from 2.4 dB to 2.0 dB.

Every mode is gated forced over a whole picture, with ffmpeg's reconstruction
equal sample for sample, and striped pictures gate the search on picking the
direction the picture runs -- a transposed predictor passes every symmetric test.
feat(av1): encode a key-frame pictureAhmet Kaan Gümüş · a4fb030
feat(av1): encode a key-frame picture

DC intra prediction over the reconstruction, the forward transform and
quantizer, and the tile writer, joined into an encoder that takes a planar
4:2:0 picture and produces a stream. Blocks are 32x32 luma and 16x16
chroma, coded in the order a decoder walks a superblock's quadrants.

The gate is an equality: ffmpeg's decode of the stream matches the
encoder's own reconstruction sample for sample, on every plane, for test
cards at three sizes and for a frame of real video. Prediction reads the
reconstruction, so a single sample of drift would spread through every
block below and to the right of it.

At q_idx 100 a 640x352 film frame costs 32 366 bytes at 39.26 dB, which is
about 2.4 dB behind libaom at the same rate -- the size of what is not
implemented yet: one block size, one transform type, DC prediction only,
no rate-distortion decision, no CDF adaptation.