Commits
Commits on
e6fcc5cc2788e495935cd800044f63dc8e2915b32026-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.
Merge branch 'lane-h265-tskip': transform skip, measured and left offAhmet Kaan Gümüş · d563e2c
Merge branch 'lane-h265-tskip': transform skip, measured and left off Transform skip is a content-dependent win: on a 2560x1440 screen capture it is worth +0.243 dB BD-PSNR (+0.030 to +0.273) and +0.158 BD-PSNR-YUV, while on a 3840x1608 film clip it costs -0.008 dB. It stays opt-in until the encoder picks it per clip.
test(h265): take the clip's dimensions by positionAhmet Kaan Gümüş · d04b63e
test(h265): take the clip's dimensions by position ffprobe prints one comma-separated line per stream and recent builds end it with a trailing separator, so splitting the line in two handed the parse a field with a comma still on it and every clip-driven gate panicked before it measured anything.
feat(av1): a superblock can stay wholeAhmet Kaan Gümüş · da2c24a
feat(av1): a superblock can stay whole
The tile writer coded every superblock as four 32x32 blocks. It now takes
a `Superblock` that is either `Whole` — one 64x64 block with a TX_64X64
luma transform and one 32x32 transform per chroma plane — or `Split` into
the four blocks it coded before, and the two paths share the mode and
plane writers.
Two contexts had to be corrected for the whole path to decode:
* the superblock partition symbol reads bit three of its neighbours'
partition context, which only a 32x32 neighbour sets, so the context
is which neighbours were split rather than which ones exist;
* the base-range tail of a 64x64 transform is coded with the 32x32
table, because the size index into that CDF is clamped there.
Both are covered: a 128x64 frame whose left superblock is whole and whose
right one is split decodes to a gradient that runs the full sixty-four
samples beside four quadrants that fall on their own, and reverting
either context fails it.Merge branch 'lane-av1-golomb': the Golomb tail for large levelsAhmet Kaan Gümüş · d74818fBrowse files
feat(av1): the Golomb tail carries levels the base range cannot reachAhmet Kaan Gümüş · 0eba770
feat(av1): the Golomb tail carries levels the base range cannot reach The base and base-range syntax reach level fourteen between them, and until now the writer refused anything above it. The spec carries the rest as a Golomb tail — the remainder plus one, as its bit length in unary followed by its own bits — written after the coefficient's sign rather than beside its level, which is where `write_golomb` now puts it. The refusal moves up to the largest level the spec's twenty-bit reader can read back. Two gates. The spec's own `read_golomb`, written from the pseudocode, must hand back the level that was asked for over the whole range, which fails the moment the tail is a bit long, a bit short, or written against the wrong base. And ffmpeg must decode a run of DC levels either side of the threshold into a run of steadily brighter blocks, with the negatives of the same levels steadily darker, which fails if the tail lands in the wrong place in the syntax.
Merge branch 'lane-av1-partial': partial superblocks at the frame edgeAhmet Kaan Gümüş · 56f5ba6Browse files
feat(av1): frames that are not a whole number of superblocksAhmet Kaan Gümüş · 7f9b390
feat(av1): frames that are not a whole number of superblocks A superblock at the right-hand or bottom edge of a frame may be half outside it. The spec codes that case as a gathered two-symbol flag — split_or_horz when the right half is missing, split_or_vert when the bottom half is — rather than the full partition symbol, and infers the split with no symbol at all when both halves are outside. The gather sums the probability of every partition type the flag stands for, which is what `gather` builds from the partition CDF. The coefficient writer now sizes its block grid from the frame rather than from whole superblocks, refuses only frames that are not a whole number of 32x32 blocks, and skips the quadrants that fall outside. The gate decodes a 96x64 frame — a superblock and a half across — whose six blocks alternate between a basis function flat down the block and one flat across it, so a block written into the wrong place or a flag read as a different number of bits shows up as the other block's shape. Three mutations fail it: writing the full partition symbol at the partial superblock, coding the out-of-frame quadrants, and (already) sizing the grid off superblocks.
feat(av1): code a real intra mode per blockAhmet Kaan Gümüş · 6cacc2b
feat(av1): code a real intra mode per block The tile writer coded DC_PRED for every block. It now takes the luma intra mode with the block's coefficients and codes it against the key-frame CDF the block's neighbours select, with the angle delta a directional mode carries. The chroma mode stays DC_PRED, but the table it is coded with is indexed by the luma mode — holding the DC row while the luma mode moved desynchronised every stream, which is what the new decode test caught first. A dav1d decode gates the result on what the modes promise rather than on pinned bytes: the top-left block carries a basis function that is flat across it and falls down it, the block to its right is H_PRED and must repeat its left neighbour's column, and the block below is V_PRED and must repeat the row above it. Dropping the angle delta, pinning the mode context or pinning the chroma table each fail it.
feat(h265): transform skip on 4x4 transform unitsAhmet Kaan Gümüş · f5dbd0b
feat(h265): transform skip on 4x4 transform units A 4x4 transform unit may now code its residual samples directly instead of transforming them (transform_skip_flag, 7.3.8.11), which is what screen content wants: sharp edges spread over every basis function, and the transform costs bits to undo them. The PPS carries transform_skip_enabled_flag, the flag itself is coded per 4x4 TU on its own pair of contexts (luma and chroma, init value 139 in Table 9-25), and the residual path swaps the integer transform for a pair of shifts. Those shifts are the whole feature: the decoder scales what it reads by tsShift = 5 + Log2(nTbS) and takes the bit-depth shift of 12 back off, so a coefficient carries the sample scaled by the difference. Writing the encoder's own shift as tsShift instead was caught by the decode: 3117 samples of a 64x64 picture differed. Off by default, so every existing stream stays byte-identical; the BD gate reaches it through EC_H265_TSKIP. Gated by ffmpeg decoding three picture shapes sample for sample against the encoder's reconstruction, and by a unit round trip over every 8-bit residual value. Three mutations were checked to fail those: tsShift one short, the flag never written, and one wrong context init value.
Merge branch 'lane-av1-chroma': chroma coefficients beside the luma onesAhmet Kaan Gümüş · a863c19Browse files
feat(av1): code chroma coefficients beside the luma onesAhmet Kaan Gümüş · b99ade1
feat(av1): code chroma coefficients beside the luma ones The coefficient writer took a luma coefficient list per 32x32 block and wrote both chroma transform blocks as all-zero. It now takes a BlockCoeffs per block — luma, U and V — and codes each plane's own 16x16 chroma transform. The coefficient layer is generalised over the plane rather than duplicated: a TxbCoding carries the transform's side and the six default CDF sets that are indexed by plane type and transform size, plus the end-of-block alphabet, which is a quarter the size at 16x16. The chroma all-zero flag reads the context its coded neighbours above and to the left select, so the writer now tracks per plane what each block left behind rather than only the sign of its luma DC. Gated by dav1d decodes of derived structure, not pinned bytes: a chroma basis function must be flat down the block and fall across it, the plane turned a quarter turn must do the reverse, neither may reach the other plane or luma, and a block with no DC must average to its prediction. Three mutations were checked to fail those tests: chroma reading the luma base table, the chroma all-zero context pinned at 7, and the chroma end-of-block alphabet taken from luma.
Merge branch 'lane-av1-ac': coefficients anywhere in a 32x32 transformAhmet Kaan Gümüş · bf55815Browse files
feat(av1): code coefficients anywhere in a 32x32 transformAhmet Kaan Gümüş · 0dac984
feat(av1): code coefficients anywhere in a 32x32 transform The tile writer could put one DC coefficient in a block. This adds the rest of the coefficient syntax: an end-of-block position with its group offset, the base levels of every coefficient down the scan with the contexts its neighbours and its position give, the base-range tail with its own contexts, and the signs — the DC's from a CDF and the rest as raw bits. The default scan is written as the rule that generates it rather than a thousand pinned numbers: it walks the anti-diagonals outwards, and the test checks the rule against what a scan must be — every position once, the origin first, and every context neighbour of a position scanned before it, which is what lets a decoder read a context off coefficients it already has. The gates decode through ffmpeg and assert structure rather than pinned samples: a coefficient off the origin decodes to its own basis function (rows identical, samples falling across the block), a block with no DC averages to its prediction, and a coefficient in the far corner reaches the last end-of-block group, whose offset is nine bits wide.
Merge branch 'lane-av1-split': 32x32 blocks in the AV1 tile writerAhmet Kaan Gümüş · 7bce6fbBrowse files
feat(av1): split superblocks into 32x32 DC blocksAhmet Kaan Gümüş · a25e4a3
feat(av1): split superblocks into 32x32 DC blocks The tile writer coded one 64x64 block per superblock, which left the partition syntax with one value it ever wrote and the coefficient path with one transform size it ever used. A superblock can now be split into four 32x32 blocks, each carrying its own DC level: the split partition itself with the context its neighbours' block sizes set, the 32x32 partition below it, the chroma mode from the table a CFL-capable block reads, and the coefficients on the 32x32 CDFs. The coefficient body the two writers share is factored out with its tables passed in, since only the tables differ. The gate decodes a four-by-four grid of 32x32 blocks over two by two superblocks, with alternating signs so the walk crosses superblock boundaries in both directions and the DC sign context lands on all three of its values. Every sample is checked against the DC prediction from the block's reconstructed neighbours plus its own pinned residual.
Merge branch 'lane-av1-signctx': per-superblock DC levels and sign contextAhmet Kaan Gümüş · 7ac6fa6Browse files
feat(av1): a DC level per superblock, with the real sign contextAhmet Kaan Gümüş · 154aa4b
feat(av1): a DC level per superblock, with the real sign context The tile writer carried one level for the whole frame, which meant every block saw the same DC sign context and the context derivation was never observed: a frame of one sign reaches two of the three contexts and never the one where the neighbours cancel. Levels now arrive one per superblock, and the sign context is read off the blocks above and to the left the way a decoder reads it -- each 4x4 unit of a coded neighbour voting its sign, the left column dropped at the start of every superblock row. The gate decodes two 128x128 grids whose levels differ in sign and checks every sample of every block. Its expectation is derived rather than pinned this time: a block's grey is the DC prediction from its reconstructed neighbours plus its own residual, so the test also holds the prediction propagating across the frame, which the single-block frames could not.
Merge branch 'lane-av1-coeff': DC coefficient coding in the AV1 tileAhmet Kaan Gümüş · f830031Browse files
feat(av1): code a DC coefficient in the key frame tileAhmet Kaan Gümüş · c68b3bd
feat(av1): code a DC coefficient in the key frame tile The tile writer could only say "this block is skipped". It now carries a single luma DC coefficient through the full coefficient syntax: the all-zero flag, the end-of-block position, the base level, the base-range tail for levels above two, and the sign with its neighbour-derived context. Chroma stays all-zero, so the two chroma flags sit immediately after the luma block and a desync in it lands on them first. The q-context CDFs this crate carries are the ones for base_q_idx 61..=120, so the writer refuses a base_q_idx outside that band rather than coding against tables the decoder will not be using. Levels are bounded at +/-14, which is what the base syntax reaches before the Golomb tail. The gate decodes each level -14..=14 through ffmpeg and asserts the whole 64x64 luma plane lands on a pinned value, chroma is untouched at 128, the sequence is monotone in the level, and the sign moves the picture the way it should. The pinned values come from the decoder, not from a derivation: there is no inverse transform in this crate yet to derive them with.
test(bd): refuse a sample window with nothing in itAhmet Kaan Gümüş · 7642b35
test(bd): refuse a sample window with nothing in it A clip-driven BD run whose sample window is a film's black head codes to almost no bits and decodes back to the source exactly, so every point on both curves sits at the 99 dB PSNR cap, the two cubics coincide, and the gate prints +0.000 dB. That is not a measurement, and it read as one: an ablation re-measure reported the same +0.000 for both arms of the knob. Both BD gates now refuse such a window by name and say which variable samples past it. The h265 gate also fails with "ladder collapsed" when its QP shift clamps two ladder points onto the same QP, instead of the "singular BD-PSNR fit" assert deep inside the cubic solver.
feat(av1): first frame that a real decoder decodesAhmet Kaan Gümüş · 304ec65
feat(av1): first frame that a real decoder decodes A tile payload writer for the one block coding the encoder can produce so far: a key frame whose every superblock is one skipped 64x64 DC-predicted block. Four symbols per superblock — the partition, the skip flag and the two intra modes — with the frame header turning off everything that would add syntax the writer does not code yet (CDEF, loop restoration, filter intra, screen content tools, transform size selection, CDF adaptation). The default CDF tables of spec section 9.4 arrive with it, in the same orientation the symbol coder reads: the partition, skip, key-frame luma mode and CFL-free chroma mode tables, which is what this syntax touches. Gated end to end rather than by roundtrip: the stream is handed to ffmpeg and every sample of the decoded frame must be 128, which is what a DC prediction with no neighbours and no residual produces. Any desync between our arithmetic coder and dav1d's shows up as a decode failure or a sample that is not mid-grey, with no metric in between to hide it. Frames that are not a whole number of superblocks are refused by name: a partial superblock forces the partition syntax down the block tree.
Merge branch 'lane-h265-chroma': RDOQ, +0.114 dB film / +0.122 dB screenAhmet Kaan Gümüş · d951540Browse files
feat(h265): rate-distortion quantisationAhmet Kaan Gümüş · 21ef192
feat(h265): rate-distortion quantisation
Every non-zero level up to 2 is offered its lower magnitudes and zero, and
the alternative is kept when the rate the CABAC coder actually charges for
it, priced against the transform-domain error the change costs, comes out
cheaper. The rate comes from the coder itself: a counting CabacEncoder is
restored to a fixed base state per trial and asked to code the block, so
the price includes the significance map and the greater-than-one flags
rather than a model of them. Distortion is converted from the coefficient
domain to sample squared error by (n * n) / 128^2, which is what this
transform's scaling leaves for a block of side n. A whole-block-zero trial
follows, since the cbf flag alone can be the cheaper coding.
With a downward-only search the quantiser feeding it must not already
round down, so the RDOQ path quantises with a round-to-nearest offset
(dead zone 2) instead of the intra default of 3; the search then decides
what to drop. All four constants were swept against the clip gate:
luma dead zone 1/2 +0.360, 1/3 +0.315, 1/4 +0.118 (film BD-PSNR-YUV)
chroma dead zone kept at 1/2: 1/3 and 1/4 climb on luma (+0.568/+0.585)
while all-plane BD-PSNR falls (+0.169/+0.128)
max level 1 -> +0.244, 2 -> +0.276, 3 -> +0.277
lambda 1.0 -> +0.276, 1.25 -> +0.294, 1.5 -> +0.293 on film,
but -0.392/-0.408/-0.441 on screen capture
Measured on the real clips, default on:
1080p film +0.246 -> +0.360 dB BD-PSNR vs x265
2560x1440 screen capture -0.479 -> -0.357 dB
Bit exactness is gated separately: rdoq_decodes_bit_exactly encodes three
frame shapes at QP 27, asserts the bitstream differs from the plain path,
and decodes each with ffmpeg against the kept reconstruction with zero
sample mismatches.
The synthetic fallback clip in the BD gate needed its ladder alignment
extended for this: our curve now spans a much wider bitrate range than
x265's over the same QP spacing, so after the geometric-mean rates match,
the ladder is drawn in towards its own centre until both curves cover the
same range. Single-QP shift corrections are ignored, which only made the
alignment oscillate between neighbouring shifts.feat(av1): symbol coder for tile payloadsAhmet Kaan Gümüş · a580965
feat(av1): symbol coder for tile payloads AV1 specifies only the decoding process for its multi-symbol arithmetic coder, so the writer is derived as the inverse of section 8.2: it narrows the same interval decode_symbol tracks and flushes the shortest prefix that pins the interval down whatever bytes follow. CDF adaptation follows section 8.3.2, and CDFs are stored in the specification's own orientation (cumulative, 1 << 15 total, counter in the last entry) so the code reads against the spec text rather than against a decoder's internal complement. Covers the adaptive multi-symbol write, the fixed-CDF write, and L(n) literals; the flush handles carry propagation through the precarry buffer. Gated by a decoder written separately from the section 8.2 pseudocode: alphabets of 2..=16 symbols roundtrip over 4000 adaptive symbols each, 2000 mixed-width literals roundtrip, a 3000-item interleaving of both roundtrips, and a 1-in-256 stream is asserted to cost under a quarter bit per symbol so a backwards interval narrowing cannot pass. This is the primitive every AV1 tile payload is written through; the OBU writers so far cover only the headers around it.
feat(h265): sign data hiding, correct and shipped offAhmet Kaan Gümüş · 0877a36
feat(h265): sign data hiding, correct and shipped off Implements sign_data_hiding_enabled_flag per 7.3.8.11: for each 4x4 sub-block whose first and last significant scan positions are more than three apart, the sign at the first position is not coded and the decoder infers it from the parity of the sub-block's summed absolute levels. The encoder nudges one already-non-zero level by one when the parity comes out wrong, picking the coefficient whose ideal (pre-rounding) level sits closest to the nudge. Proven bit-exact: sign_hiding_decodes_bit_exactly encodes 64x64, 130x66 and 352x288 with hiding on and off, asserts the streams differ, and decodes both through ffmpeg with zero sample mismatches. Shipped off. On the clip gate it loses: -0.033 dB BD-PSNR on a 2560x1440 screen capture (-0.479 -> -0.512 vs x265) and -0.043 dB on 1080p film (+0.246 -> +0.203). Hiding is mandatory for a qualifying sub-block, so every one of them pays whether its cheapest nudge is cheap or not, and levels straight off the quantiser's rounding make that nudge expensive. A rate bias on the nudge picker was swept at +-0.25 and +-0.5 units of squared level error per bit and lost in both directions, so the picker is distortion-only. Worth re-measuring once RDOQ lands, which is where this pays for other encoders.
feat(h265): four 4x4 intra partitions in an 8x8 CU (PART_NxN), on by defaultAhmet Kaan Gümüş · 089675b
feat(h265): four 4x4 intra partitions in an 8x8 CU (PART_NxN), on by default An 8x8 coding unit may now split into four 4x4 intra partitions: the CTU encoder codes both and keeps whichever wins the rate-distortion trial, rolling back the CABAC state, the reconstruction and the mode metadata together when 2Nx2N wins. Syntax order follows the standard: the single `part_mode` bin, then four `prev_intra_luma_pred_flag` bins, then the four remainders, then the chroma mode; the transform split at depth 0 is inferred from IntraSplitFlag, `cbf_cb`/`cbf_cr` stay at depth 0, and the chroma residual rides on the last partition. Measured against x265 with self-aligning QP ladders: a 2560x1440 screen capture goes from -2.619 dB BD-PSNR to -0.479 dB (-2.502 to -0.542 YUV), and 1080p film moves +0.007 dB. It never loses, so it defaults on. The conformance test encodes the grainy natural frame rather than the synthetic one -- the synthetic frame is flat enough that the quadtree never keeps an 8x8 coding unit, so PART_NxN could not fire and the decode proved nothing.
fix(h265): bound the clip gate's decode to the pictures it samplesAhmet Kaan Gümüş · 6e90b9d
fix(h265): bound the clip gate's decode to the pictures it samples `clip_sources` asked ffmpeg for the whole file as raw I420 and sliced the result afterwards. A 1080p feature is hundreds of gigabytes that way: a run on a full film grew the test binary to 29 GB of anon RSS and was killed by the kernel OOM killer, with the machine swapping hard. Short captures fit, so the gate had only ever been run on content that hid it. Trim inside ffmpeg instead -- `select=gte(n,SKIP)` drops the skipped pictures and `-frames:v WANT` stops the decode once enough have come out, so the process holds exactly the frames it measures. The same film run now finishes in 10 s inside an 8 GB cap, and the numbers on the short capture are unchanged.
feat(av1): write the key-frame header OBUAhmet Kaan Gümüş · e203345
feat(av1): write the key-frame header OBU The inverse of `ec_av1_syntax`'s `parse_uncompressed_header`, for the subset a stateless encoder emits: a shown key frame in a sequence with no decoder model, no frame id numbers and no still-picture shortcut. It covers tile info (uniform spacing), quantization, segmentation, delta q and delta lf, loop filter, CDEF, loop restoration, transform mode and the reduced transform set, plus `frame_obu` to carry the header and a tile group in one OBU. Two of the codings are not the value they look like and are spelled out here: the restoration type is remapped (None 0, Switchable 1, Wiener 2, Sgrproj 3, not the enum's discriminant) and a CDEF secondary strength of 4 is coded as 3. Everything outside the subset is refused by name rather than written wrong: a superres denominator other than 8, film grain synthesis, frame id numbers, decoder model timing, `show_existing_frame`, any non-key or hidden frame, and non-uniform tile spacing. The tests parse back every stream they write through `Av1Parser` and compare the whole `FrameHeader`, including the derived fields the format never codes (the header's own bit length, the tile start ramps, the segmentation id range), across a one-tile frame, a four-tile-column frame, a segmented frame with delta q and delta lf, and a frame using loop restoration.
Merge branch 'lane-h265-chroma': chroma mode search, measured and left offAhmet Kaan Gümüş · 9d66338Browse files
feat(h265): chroma prediction mode search, measured and left offAhmet Kaan Gümüş · fea923b
feat(h265): chroma prediction mode search, measured and left off Chroma was always coded in the derived mode: `intra_chroma_pred_mode` was a hardcoded 0 bin. The syntax offers five modes — planar, vertical, horizontal and DC, each swapped for angular 34 when it collides with the luma mode, plus derived — and nothing had ever measured what the other four are worth. `choose_chroma_mode` now codes all five into a counting CABAC snapshot, both planes and their residuals, and keeps the lowest `SSD + lambda * bits`. It is off by default, because measured against x265 on four real clips it is a wash (BD-PSNR luma / all-plane, derived -> search): | clip | derived | search | |------|---------|--------| | 4K film | -0.685 / -0.703 | -0.757 / -0.606 | | 1138x640 web | -0.507 / -0.556 | -0.584 / -0.505 | | 1440p screen capture | -2.465 / -2.360 | -2.617 / -2.460 | | 1080p phone | -0.366 / -0.387 | -0.477 / -0.384 | Luma falls on every clip — the extra chroma bits come out of the same budget at a fixed QP — while all-plane gains 0.10 dB and 0.05 dB on the two camera clips, is flat on the third and loses 0.10 dB on the screen capture, for 10-15% more encode time. Average +0.01 dB all-plane is not a default. The lambda is not the cause: `chroma_rd_weight` swept at 0.25/0.5/1.0/2.0 leaves the screen capture losing at every weight, and 1.0 is the best weight wherever the search wins at all. Correctness is gated on its own: `chroma_mode_search_decodes_bit_exactly` asserts the stream differs from the derived-only one (so the explicit modes really fired) and that ffmpeg decodes it sample-for-sample. EC_H265_CHROMA_RD and EC_H265_CHROMA_W in the BD gate re-run both sweeps.
Merge branch 'lane-h265-rdo': five intra candidates reach the rate-distortion trialAhmet Kaan Gümüş · 966bf25Browse files
perf(h265): give five intra candidates the rate-distortion trialAhmet Kaan Gümüş · b24f633
perf(h265): give five intra candidates the rate-distortion trial The luma mode search screened 35 intra modes with SATD and handed only two survivors to the full rate-distortion trial. That count was never measured; it was the number the search was written with. Swept against x265 at matched features on four real clips (BD-PSNR luma / all-plane, 24 pictures after 1500, ladders auto-aligned, 0% extrapolation): | k | 4K film | 1138x640 web | 1440p screen capture | 1080p phone | |---|---------|--------------|----------------------|-------------| | 1 | -0.840 / -0.815 | -0.728 / -0.733 | | | | 2 | -0.731 / -0.730 | -0.603 / -0.632 | -2.521 / -2.420 | -0.435 / -0.444 | | 3 | -0.703 / -0.709 | -0.556 / -0.596 | -2.493 / -2.402 | -0.401 / -0.416 | | 4 | -0.693 / -0.705 | -0.530 / -0.574 | | | | 5 | -0.685 / -0.703 | -0.507 / -0.556 | -2.465 / -2.360 | -0.366 / -0.387 | | 8 | -0.684 / -0.710 | -0.471 / -0.525 | -2.453 / -2.368 | -0.340 / -0.361 | Every clip improves monotonically to five. Eight buys +0.001 dB on the film clip and takes its all-plane figure backwards, for another 20% of wall time, so the knee is where the default now sits: film 38s -> 49s for the whole four-QP ladder, web clip 8s -> 11s. The synthetic floor moves with it (+2.456 -> +2.507 luma, +3.158 -> +3.238 all-plane) and EC_H265_RDO_CANDIDATES in the gate test re-runs the sweep.
perf(h264): choose the Intra_8x8 luma mode by rate-distortionAhmet Kaan Gümüş · ccc4650
perf(h264): choose the Intra_8x8 luma mode by rate-distortion The Intra_8x8 chooser scored the nine prediction modes on SATD of the prediction residual plus a mode-bit term. That is a decision taken before the quantiser has a say: it never sees which mode's residual survives quantisation cheaply. Same class as the intra chroma chooser fixed in 98d01b7, and the last SATD-only intra site. Every allowed mode is now predicted, coded at the real QP and scored as SSD + lambda * bits, with the rate read from the CABAC coder's own 8x8 price (residual_block_8x8_cost — Luma8x8 has no coded_block_flag of its own, the CBP carries it, so the cbf-indexed cost path panics on it). BD-PSNR against x264 at matched features, 8x8 transform on, GOP 10, 24 consecutive pictures, luma / all-plane YUV: 3840x1608 film +0.475 / -0.068 -> +0.512 / -0.035 1138x640 web clip +0.040 / -0.031 -> +0.076 / +0.003 854x480 web clip +0.070 / +0.047 -> +0.132 / +0.108 2560x1440 screen -0.206 / -0.199 -> -0.215 / -0.207 Three clips of four gain on both metrics; the screen capture loses 0.008 dB. Encode time on the 854x480 clip goes from 12 s to 13 s. The path only runs when the 8x8 transform is enabled, which is still opt-in, so no default stream byte moves; the byte-identity conformance tests confirm it.
2026-08-24
feat(ec-av1): OBU header/framing writer + sequence-header writerAhmet Kaan Gümüş · 4cb83b2
feat(ec-av1): OBU header/framing writer + sequence-header writer Bit-exact inverse writers of the parsers in ec-av1-syntax: obu.rs: - obu_type_code: ObuType -> 4-bit code (inverse of ObuType::from_code) - write_obu_header: writes OBU header (spec 5.3.2), forbidden/reserved bits 0 - wrap_obu: frames payload as low-overhead OBU (header + leb128 size + payload) - temporal_delimiter: the two-byte 0x12 0x00 temporal-unit marker sequence.rs: - write_sequence_header: full sequence-header payload (spec 5.5.1) - write_color_config: color_config() inverse (spec 5.5.2) - sequence_header_obu: wraps the payload as a SequenceHeader OBU Supported subset only (unsupported configs return Error::unsupported): - reduced_still_picture_header == false (still-image header not implemented) - no timing_info - no decoder_model_info - exactly one operating point Roundtrip tests: write -> parse back -> assert equality for both OBU headers (plain + extension) and sequence headers; wrapped OBU leb128 size asserted to match payload length; temporal delimiter asserted to be [0x12, 0x00]. Gates: cargo test --release -p ec-av1 (13 passed), cargo clippy --release -p ec-av1 --all-targets (clean), cargo fmt.
Merge branch 'lane-h265-gate': BD-PSNR against x265 with self-aligning laddersAhmet Kaan Gümüş · addbfd0
Merge branch 'lane-h265-gate': BD-PSNR against x265 with self-aligning ladders Adds the ec-h265 gate: BD-PSNR and BD-PSNR-YUV against x265 at matched features, both sides decoded through ffmpeg, with the QP ladders aligned from a probe encode so the Bjontegaard integral interpolates. The extrapolation share of each curve is measured and a run above 20% fails with a named message instead of reporting a cubic guess.
test(h265-gate): align the QP ladders from a probe encodeAhmet Kaan Gümüş · 8b6026d
test(h265-gate): align the QP ladders from a probe encode A fixed QP offset assumed our encoder is always leaner than x265 at matched QP. That holds on the smooth synthetic clip (probe shift -6, reproducing the hand-picked 16/20/24/28) but not on real content: on a 3840x1608 film and a 1138x640 web clip the probe measures a shift of 0, and the hand-picked ladder put 51% and 72% of the integration range outside the measured bitrate span, so the guard fired and the BD number would have been a cubic guess. The ladder is now derived: both sides encode once at QP 26, the bit ratio becomes a QP shift at ~6 QP per factor of two in bits, and x265's 22/26/30/34 plus that shift is our sweep. If the extrapolation share still exceeds 20%, the shift is re-estimated from the geometric-mean bit ratio of the two full curves, at most twice, before the existing panic fires. The probe encodes are reused as the QP-26 rungs, so the alignment costs no extra encode. With the ladders aligned, the real gap is visible: -0.731 dB luma / -0.730 dB YUV on the film, -0.603 dB / -0.632 dB on the web clip, 0% extrapolation on every curve. The synthetic floor stays at +2.306 dB and gates only the pinned clip; a media file is measured, not gated. Two comments corrected while here: ffmpeg's `-qp` does reach libx265 (`qp=N` and `rc=cqp:qp=N` are byte-identical, so the prefix is dropped), and the shallow all-intra rate-quality slope is content behaviour, not a rate-control misconfiguration.
feat(ec-av1): bit-primitive writers (leb128/uvlc/le/su/ns/delta_q/trailing_bits) with roundtrip testsAhmet Kaan Gümüş · d869345Browse files
perf(h264): choose the intra chroma mode by rate-distortionAhmet Kaan Gümüş · 495e450
perf(h264): choose the intra chroma mode by rate-distortion The chooser scored the four chroma prediction modes on SATD of the prediction plus the bits naming the mode, deciding before the quantiser had a say. Every available mode now goes through the real chroma coding path and is scored on reconstructed SSD plus what its levels and its name actually cost, which is the same measurement the rest of the macroblock decisions already make. Measured with bd_psnr_vs_x264 against x264 -preset medium, BD-PSNR-YUV, GOP 10, 24 consecutive pictures: 3840x1608 film -0.500 -> -0.443 dB, 2560x1440 screen capture -0.220 -> -0.146 dB, its second scene -0.571 -> -0.538 dB, a 1080p phone clip -1.122 -> -1.084 dB, a 720p web clip -0.606 -> -0.572 dB. Five clips of five improve; luma is unmoved (film -0.065 -> -0.070 dB) and encode time does not change measurably, since only intra macroblocks pay and only four chroma trials each.
fix(h265-gate): offset QP ladders so BD-PSNR is a measurement, not a guessAhmet Kaan Gümüş · 4ae6e08
fix(h265-gate): offset QP ladders so BD-PSNR is a measurement, not a guess The gate reported BD-PSNR -38.258 dB with 50% extrapolation on our side — the two rate-quality curves did not overlap. Root cause was misdiagnosed as ffmpeg -qp not reaching x265 rate control; in fact -qp and rc=cqp:qp=N produce byte-identical output. x265 at CQP on this smooth synthetic clip genuinely has a shallow rate-quality slope (29% bitrate drop across 12 QP). The fix: pass rc=cqp:qp=N inside the x265 param string (explicit, not relying on ffmpeg flag translation) and offset the QP ladders so the bitrate ranges overlap. Our sweep drops to 16/20/24/28; x265 stays at 22/26/30/34. At matched bitrate our PSNR is higher on this clip. Measured table (352x288, 24 pictures, Clip::render_smooth): qp 16: ours 809632 bits 53.63 dB qp 20: ours 577872 bits 51.26 dB qp 24: ours 433584 bits 48.84 dB qp 28: ours 316664 bits 45.86 dB qp 22: x265 835424 bits 51.50 dB qp 26: x265 745104 bits 49.19 dB qp 30: x265 674088 bits 46.37 dB qp 34: x265 596808 bits 42.97 dB cubic extrapolation: candidate 0% anchor 0% BD-PSNR: +2.456 dB luma / +3.158 dB YUV Guard: bd_psnr_delta now returns (bd, cand_extrap, anc_extrap); the test panics with a named message when either curve is extrapolated over more than 20% of the integration range. Floor recalibrated: BD_PSNR_VS_X265_FLOOR = 2.306 (measured 2.456 - 0.15).
perf(h264): give the chroma DC block a zero testAhmet Kaan Gümüş · 59070a1
perf(h264): give the chroma DC block a zero test Every other block in this encoder is asked whether coding it pays: luma 4x4 and 8x8, the chroma AC group, the macroblock's shape and skip flag. The chroma DC block was the exception — whatever the quantiser produced was coded, however little it bought. It gets the same test now. With only DC in a block the inverse transform gives every one of its sixteen samples the same (dc + 32) >> 6, so the squared error of zeroing the block is exact from the AC residual that is already reconstructed at that point: one sum per block, no second trial. BD-PSNR-YUV against x264 (GOP 10, QP 22/26/30/34, Preset::Balanced), test off -> on: film -0.504 -> -0.500, screen capture -0.227 -> -0.220, phone -0.300 -> -0.297, handheld -0.886 -> -0.884. The multiplier's ladder is in the comment on CHROMA_DC_LAMBDA; the peak is flat between 0.5 and 0.75 and turns sharply worse above 1.
ec-h265: add bd_psnr_vs_x265 gate against x265Ahmet Kaan Gümüş · 15b6d35
ec-h265: add bd_psnr_vs_x265 gate against x265 BD-PSNR of this encoder against x265 at matched features (intra-only, no B frames, in-loop filters off, AQ/psy/RDOQ off, QP 22/26/30/34) on the synthetic 352x288 24-picture clip, both sides decoded through ffmpeg. Measured: BD-PSNR luma -38.258 dB, BD-PSNR-YUV -31.656 dB. Floor calibrated at measured - 0.15 = -38.41 dB. The gap is wide because this encoder spends 40-70% fewer bits than x265 at every QP, so its rate-quality curve sits below x265's and the union-range cubic integral extrapolates; the convention is documented in bd_psnr_delta.