* av1enc: motion search with a visited set and early-exit SAD, fixed-size SATD, region-only BlockDecoded snapshot
- motion_search remembered nothing: the diamond search evaluated the previous
centre again and every SAD ran to the last row even when it had already
lost. Full-sample and sub-sample positions are now tracked in a visited
list (costs are deterministic, so a position that was evaluated cannot beat
the best cost again), and the SAD stops after a row once sad + mv cost can no
longer be below the best cost. The stop test is the same f64 expression as
the strict "<" the callers apply, and it is monotone in the SAD, so the
chosen vector is the same.
- satd runs with a fixed block size (satd_k::<4> / satd_k::<8>): the
difference block is a [[i32; K]; K], the vertical butterflies work on whole
rows at once, and the old per-column gather is gone. The sum is an integer
sum of the same values.
- A snapshot copies only the BlockDecoded cells of the block area (at most
16x16 per plane), the only flags coding inside the block can change, instead
of the whole 3x35x35 array.
The encoded stream is unchanged. A unit test compares the new SATD with the
previous implementation for 4..32 sample blocks at 8 and 10 bit.
Fixes#2387
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* av1enc: tests for the region-only BlockDecoded snapshot and the bounded SADs
- `snapshot_restore_brings_back_every_blockdecoded_flag`: for every block
size of a 64x64 superblock (4x4 .. 64x64) at every aligned position in two
superblocks, from an all-clear and a random flag state, marking every
sub-block of every size inside the block and restoring gives back the whole
3x35x35 array, so the 16x16 region covers every flag coding can set and
leaves the neighbours alone.
- `bounded_sad_stops_only_once_the_cost_cannot_win`: `sad_ref` and
`sad_bounded` return the full SAD whenever `sad + lb < bound`, and
otherwise a partial sum that already loses the strict `<` of the callers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
Every MP4 export said BT.709 whatever the Output color space, in the
colr box and in the bitstream, so Rec. 2020, P3, PQ and HLG renders
were labelled as BT.709.
Move the ProRes colr mapping to output_codes and use it for every movie
path: the nclx colr box, FilmCraft's H.264 ColorConfig (VUI), and new
colour fields in effectcraft-hevcenc (VUI) and effectcraft-av1enc
(color_config), which wrote 1-1-1 as constants. The matrix stays BT.709,
the coefficients every path converts with. Default renders don't change.
The strict-clippy split of inverse_dct (#2496) passes n at run time; inlining keeps
inverse_dct_n's compile-time sizes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve crates/av1enc/src/decide.rs: main replaced the long try_tx/code_tx
argument lists with the TransformBlock struct. try_tx and code_tx keep the
branch's scratch-buffer design (TxScratch taken out of the decider) and take
a TransformBlock; reconstruct now takes its three output buffers as a
ReconBuffers struct to satisfy the denied clippy::too_many_arguments.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Bitrate mode coded the first frame four times with a fixed gain. Now the
first pass still gets the old correction (30 quantizer steps per halving
of the size, which fits the starting range), and from the second
correction on the next quantizer is placed in the log domain of the
quantizer step, where the frame size is close to a line: false position
between the nearest passes that enclose the target, otherwise a secant
step with the measured slope. The search stops as soon as the size is
within 3 % of the target, when no untried quantizer is left between the
enclosing passes, or when it would repeat a quantizer (a target the
content cannot reach, where the old code coded the same frame at the
lowest quantizer up to four times). At most four passes remain.
The first frame is within 3 % of the target on the same cells as before
and nearer to it on most of the others; two cells where the size jumps
by a factor of 4 or more between neighbouring quantizers (noisy content)
land further away than with the old search. Total passes over the 28
test cells: 112 -> 70.
Part of #2390
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Bitrate mode gave key frames keyint-dependent extra bits (about 6.8 frame
budgets at the 60 frame default) but left the inter frames at the full
frame budget, so every group of frames overshot by (boost - 1) / keyint,
9.6 % at keyint 60 (up to +187 % at keyint 5 on some content). The
accumulated deviation was tracked against the boosted budget, so the
feedback never saw it.
Now a group of keyint frames adds up to keyint * frame budget: inter
frames get (keyint - boost) / (keyint - 1) of it. Further changes to the
frame level control:
- The quantizer follows the size error with a measured slope (quantizer
steps per halving of the size, taken from consecutive inter frames)
instead of a fixed 12 steps per doubling. On noisy content the curve is
several times steeper than that and the old gain oscillated between
1 kB and 42 kB frames.
- Key frames have their own quantizer offset, adapted from key frame
sizes only, instead of feeding the key frame error into the inter
quantizer. A key frame after the first that misses its budget by more
than 19 % is coded again (at most twice more), with a corrected
quantizer found in the log domain of the quantizer step.
- A deviation from the budget is paid back over 16 frames, bounded to
0.35x..2x of the budget.
Constant quantizer mode is untouched (byte identical output). The
encoded stream in bitrate mode changes.
Adds a test that the rate stays within 5 % of the target over 180
frames for three 8 bit and one 10 bit setting.
Part of #2391
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
try_tx and reconstruct allocated six Vecs per candidate (residual, coefficients,
levels, dequantised coefficients, inverse residual, reconstruction), the
coefficient writer allocated its level map per transform block, and the loop
filter level search cloned the luma plane for every candidate level.
- Decider keeps a boxed TxScratch (32x32 arrays) that try_tx and reconstruct
write into; the levels and the reconstruction of a candidate stay there and
the caller copies out only what it keeps (the winning intra candidate, or the
levels that go into the leaf). intra_leaf uses stack arrays for its
predictions and a fixed array for the mode ranking and transform types.
- TileWriter reuses one level-map Vec, and the partition CDF at frame edges is
read through a slice instead of a copy.
- The level search filters one working copy of the luma plane and restores it
from the reconstruction before each candidate.
The encoded stream is unchanged.
Fixes#2374
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Decider::new built the half-sample planes (8,0), (0,8) and (8,8) with
three full 2-D 8-tap passes (subpel_plane), each with per-tap clamping.
half_planes computes them together: the horizontal half-sample pass is
shared by (8,0) and (8,8), the phase-0 kernels are exact shifts
(Round2(128*v, 11) = Round2(v, 4), Round2(16*s, 11) = Round2(s, 7)), and
interior pixels skip the clamps.
subpel_plane is kept as the test-only reference; a new unit test checks
half_planes against it bit for bit (including 1x1, 5x3 and 10 bit).
The only change in decide.rs is the call in Decider::new.
Output is bit-identical.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The quantiser in try_tx called libm floorf for every coefficient, estimate_bits
and the motion-vector cost called f64::log2, and coefficients that quantise to
zero still went through an f32 division.
- (x / q + rnd).floor() as i32 becomes (x / q + rnd) as i32: the operand is
never negative, so truncation equals floor.
- log2 of small integers comes from a table built with the same f64::log2
call (estimate_bits and the MV cost in motion_search), so the values are
bit-identical.
- Coefficients below an exact per-(q, rounding offset) threshold are zero
without dividing. The threshold is found once per Decider by a binary
search over f32 bit patterns of the monotone quantiser expression.
The encoded stream is unchanged. Unit tests compare the new quantiser with the
old expression at the threshold boundary and on random values for every
quantiser index, and the table with f64::log2.
Fixes#2373
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The inverse transform computed its bit-reversal permutations and loop
bounds at run time and went through one generic path for every size.
inverse_dct, the ADST permutations and inverse_2d are now const generic
over the size and inlined, so the permutations fold at compile time.
forward_2d zeroed a 4 KiB tmp buffer on every call, even for 4x4. It now
dispatches to a fixed-size version for 4, 8 and 16 (tmp is exactly n*n
floats); 32 keeps the run-time version, which measured faster than a
const 32 variant. The float operation order is unchanged.
Output is bit-identical.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Replaces the encoder's 11 expect()/unreachable!() calls on internal invariants with handling
that can't panic: the rate-control state is passed in rather than re-borrowed, inter decisions
without a reference frame fall back to intra, per-plane results are bound directly, and the
writer's impossible branches become debug_asserts. Denies the panic lints in the crate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>