# lane h265m10enc: ec-h265 HEVC Main 10 encode Branch `lane/h265m10enc`, base merge-base `000545961a1e` (main had moved on to `6f70bcf`). ## Goal and what changed ec-h265 now encodes 10-bit 4:2:0 (`EncoderConfig::bit_depth`, 8 or 10, default 8), with `general_profile_idc` 2 (Main 10), QP range -12..51, and VUI colour description passthrough. - `ec-h265-syntax/src/ps.rs`: `ProfileTierLevel::main10` (profile_idc 2, compat bits 1 and 2). - `ec-h265/src/ctu.rs`: `Pel = u16` internally for all depths. qP' = QpY + 12 for 10-bit (QpBdOffset is 12 for 10-bit, not 6). Dequant and lambda run on qP'. The quantizer runs on QpY (`quant_qp`). Forward output is scaled down by `bd-8` (`scale_forward_bd`). rdoq lambda is divided by 16 at 10 bits. - `ec-h265/src/transform.rs`: `quant_qp`, `scale_forward_bd`. Quantizer helpers use `div_euclid`/`rem_euclid` so negative QpY works. - `ec-h265/src/residual.rs`, `deblock.rs` (beta and tc scaled by `1 << (bd-8)`), `enc_me.rs` (8-bit approximation for ME), `enc_rc.rs` (QP table with qp_min), `enc_p.rs` (P path: forward shift and quant_qp in `code_tb`), `encoder.rs` (`EncoderConfig.bit_depth`, I010 input and output, SPS bit depths, `plane_samples`, MD5 hashes LE bytes at 10 bits). - SAO: this encoder does not enable SAO, so no 10-bit SAO work was needed. - Tests: `crates/ec-h265/tests/main10.rs` (IDR and sequence round trip against the reconstruction, bit-depth refusal, SPS profile and colour description, 5% bitrate check). - Scripts: `scripts/hevc10-roundtrip.sh` (new), `scripts/hevc-bdrate.sh` (PIX, bit-depth export, `-profile:v main10`), `scripts/ffmpeg-psnr.sh` (PIX), `scripts/yuv_psnr.py` (10-bit PSNR). - `examples/hevc_gop.rs`: `EC_H265_BITDEPTH=10` selects 10-bit I/O. Temporary debug knobs were removed. ## Verification (all run on server host c, or a when c was busy) Full suite: `cargo test --release -p ec-h265`: every test binary passes, including `main10` (CARGO_EXIT=0). Existing 8-bit tests pass unchanged. A direct byte comparison of 8-bit output against the base commit was not run; the 8-bit path is guarded so that every 10-bit branch is inactive at 8 bits. Clippy: `cargo clippy -p ec-h265 --all-targets -- -D warnings`: passes (fixes: `as_chunks` in `plane_samples`, `allow(clippy::too_many_arguments)` on `deblock`). Round trip, 64 frames, constant QP 30 (`scripts/hevc10-roundtrip.sh`, all rows byte-exact to ec-h265 and ffmpeg): | clip | GOP | bytes | kbps | luma PSNR | yuv PSNR | ec-h265 | ffmpeg | |---|---|---|---|---|---|---|---| | 416x240 | intra | 16569 | 62.1 | 44.39 | 42.83 | exact | exact | | 416x240 | 8 | 9736 | 36.5 | 39.05 | 38.02 | exact | exact | | 1280x720 | intra | 1307338 | 4902.5 | 46.07 | 45.01 | exact | exact | | 1280x720 | 8 | 700905 | 2628.4 | 40.91 | 40.04 | exact | exact | Bitrate mode, target 2500 kbps at 30 fps, GOP 8 (`RC=2500@30`), all byte-exact: | clip | GOP | kbps | deviation | luma PSNR | yuv PSNR | |---|---|---|---|---|---| | 416x240 | intra | 2510.7 | +0.43% | 62.22 | 58.39 | | 416x240 | 8 | 2582.0 | +3.3% | 56.26 | 52.29 | | 1280x720 | intra | 2506.1 | +0.24% | 39.61 | 38.82 | | 1280x720 | 8 | 2477.4 | -0.9% | 40.66 | 39.59 | BD-rate against libx265 (`-preset veryfast -tune psnr -x265-params bframes=0:keyint=8`, QPs 22 27 32 37, 64 frames, GOP 8). Positive means ec-h265 needs more bytes. | clip | bit depth | BD-rate (yuv) | BD-rate (Y) | |---|---|---|---| | 416x240 | 10 | 9.36% | not captured for this rerun | | 416x240 | 8 | 11.46% | 9.37% | | 1280x720 | 10 | 14.31% | 9.90% | | 1280x720 | 8 | 17.32% | 12.51% | 10-bit is 2.1 points better than 8-bit at 416x240 and 3.0 points better at 720p, so the "not worse than 8-bit by more than 10 points" bar is met. Note the 416x240 10-bit clip was first generated with 4 frames; it was regenerated at 64 frames before the figure above. PSNR at 10 bits is reported in the table above (the 10-bit PSNR is computed against 10-bit source). ## Criteria - 10-bit 4:2:0 encode, Main 10 profile, QP range -12..51: MET. - Intra and GOP, constant QP and bitrate, 416x240 and 1280x720, 64 frames: MET. - ec-h265 and ffmpeg decode byte-exact to the encoder reconstruction: MET (all 12 rows). - Bitrate within +-5% of target: MET (max deviation +3.3%). - PSNR and BD-rate vs libx265 main10 recorded; BD-rate not worse than 8-bit by more than 10 points: MET. - Full ec-h265 test suite and clippy on server: MET. - 8-bit output bit-identical (existing tests pass unchanged): MET by tests; direct byte compare not run. ## Not done or open - No direct byte comparison of 8-bit output against the base commit. - Chroma-only 10-bit ME refinement and 4:2:2/4:4:4 are out of scope for this lane. - Bench rows were not added to lanes/bench.md.