edith_codecs
Clone
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
lane/h264hi444 report
What ec-h264 now decodes
- Monochrome (chroma_format_idc 0), High profile and up, 8/9/10 bit. Output is I420 (8 bit) or I010 (9/10 bit) with the chroma planes filled with the neutral value (1 << (bd-1)). ec-core has Gray8/Gray16 but I did not use them: edith's
Deep::loadand the 8-bit path already handle I420/I010, so no edith change is needed for monochrome. - High 4:4:4 Predictive (profile 244), 8 and 9/10 bit, CAVLC and CABAC, 8x8 transform, scaling matrices (12 lists), PAFF and MBAFF, weighted prediction, PCM. Output I444 (8 bit) / I410 (9/10 bit).
- CAVLC 4:4:4 Intra (profile 44) and High 4:4:4 Intra: same path.
separate_colour_plane_flag = 1: three independent monochrome decode sequences (one Core per colour_plane_id, scaling lists of the plane), merged into an I444/I410 frame on output (merge_planesin decoder.rs).- Lossless:
qpprime_y_zero_transform_bypasswith QP'Y = 0 for all three colours, including the lossless intra prediction DPCM of 8.5.15 (Intra4x4/8x8 horizontal/vertical, Intra16x16 horizontal/vertical, chroma horizontal/vertical in 4:2:0/4:2:2), I16/chroma DC without transform, and the deblocking rule that transform-bypass macroblock samples are not modified (per-edge snapshot/restore; progressive and MBAFF). - New opt-in
Decoder::set_wide_samples(true): accepts 11..14-bit streams. Frames then carry native-depth samples in 16-bit words inside I410/I010 (which only describe 10 bits). Off by default, so product behaviour (refuse above 10 bits) is unchanged. It exists because every JVT 4:4:4 conformance stream is 14-bit.
Design notes
- CABAC: Cb/Cr residual contexts 460..1023 (Table 9-34 categories 6-13) are exactly the luma init values (verified by extracting the tables from libx264); only 1012..1023 (coded_block_flag of 8x8 blocks, 4:4:4 only) are new. Context state array is 1024 wide;
init_contexts(460) stays for the encoder. - Residual: new
residual_luma_styleruns luma-style (I16 / 8x8 / 4x4, with 4:4:4 CABAC 8x8 coded_block_flag) per colour component; CBP uses the 16-entry tables for ChromaArrayType 0/3; no intra_chroma_pred_mode; PCM sample counts per ChromaArrayType. - Inter: Cb/Cr use the luma interpolation with their own weights (no chroma mv derivation); deblocking filters Cb/Cr with the luma filter, luma bS, chroma QP per side.
Sps::chroma_array_type()added in ec-h264-syntax.slice_bit_depthbecameslice_route(also peeks colour_plane_id).
Verification
- x264 sweeps vs ffmpeg byte-exact (tests/high444.rs, 11 tests, pass on server): yuv444p and yuv444p10le, CABAC/CAVLC, 8x8dct on/off, MBAFF 4:4:4, lossless (-qp 0) 4:4:4 8/10 bit, 4:2:0 and 4:2:2 lossless, gray and gray10le. HD case opt-in via EC_H264_HI444_HD=1.
- JVT professional-profile vectors (tests/high444_jvt.rs; fetched into fixtures/vectors/h264-jvt-hi444 by
scripts/fetch-vectors.sh h264-jvt, checksums in scripts/vectors.sha256):- Byte-exact against ffmpeg (gbrp14le): PPCV444I1-3, PPH444I1-3, PPH444P1-5 (14-bit 4:4:4, CAVLC and CABAC, intra and predictive; 120 frames each at 1080p).
- Mitsubishi streams (PPCV444I4-6, PPH444I4-6, PPH444P6,7,9: 14-bit, separate_colour_plane_flag=1, one with loaded Q-matrix, one with colour_plane_scrambled): decode all frames without error (so the entropy parse is exact end to end) but there is no reference yuv in the archives and ffmpeg refuses separate planes, so pixel exactness is not proven. Visual check of PPCV444I4 frame 0 gives a clean correct image ("card" sequence). I could not obtain JM.
- PPCV444I-7, PPH444I-7, PPH444P-10 (Sejong Univ.): use FMO slice groups, which ec-h264 refuses by name (outside this lane); the test reports them as skipped.
- The Hi444 JVT streams contain no lossless stream I could identify; lossless is covered by the x264 sweeps only.
- The three Mitsubishi P/B 14-bit streams and everything above ran on the server.
- Not covered: 4:4:4 Predictive 8/10-bit JVT vectors do not exist in the archive (all are 14-bit); 8/10-bit coverage is from x264 vs ffmpeg.
Perf (progressive 4:2:0 must not regress)
perf stat -e instructions:u of bench_decode <clip> 3 --hash, 1080p x264 high clips, 40 frames, before (main) and after:
- hd8.264 (bframes=3, weightp=2, ref=3, CABAC): 27,914,368,341 -> 28,413,248,976 (+1.79%), hash identical (9c0140cf3f658f3c)
- hd8b.264 (CAVLC): 40,283,975,806 -> 40,803,896,245 (+1.29%), hash identical (716ea5290d9c1c44) Both under the 2% budget; hashes are identical.
Gates (server)
cargo clippy --workspace --all-targets --release -- -D warnings: clean.EC_REQUIRE_FIXTURES=1 cargo test -p ec-h264 --release(all suites, skipping onlyreal_library_frames_encode_and_decode_exactly): passes, including the high444_jvt run above.- Vectors rsynced to ~/fixtures/vectors/h264-jvt-hi444 on all three hosts (user@host-a, host-b, host-c; excluding .zip and logs). remote-run.sh links
fixtures -> ~/fixtureson the host. - Fuzz seeds not updated: every available 4:4:4 stream is 1080p and tens of MB, too big for seed.sh.
What edith needs (not applied)
Where edith refuses: crates/engine/src/demux.rs avc_bit_depth (4:0:0, 4:4:4 and transform_bypass refused by name, plus the avc_refusal text), and crates/engine/src/decode.rs Deep::load, which only converts I010/I210/I422 to the engine's 4:2:0 planes (I444/I410 would fall into the _ => branch and be treated as plain I420, which is wrong).
Also to adjust: crates/engine/tests/interlaced_h264.rs::four_four_four_monochrome_and_lossless_are_refused_by_name (expects the refusals), and the doc strings that say H.264 is 4:2:0/4:2:2 only (avc_refusal text, covered in the diff). crates/mcp/src/help.rs only lists HEVC 4:4:4/4:0:0 and needs nothing. Monochrome needs no decode.rs change (I420/I010 with neutral chroma).
video_profile.rs and colorspace.rs already name profile 244/44 and know Chroma::C444/Gray.
Not compiled against edith (read-only); the closure signature in Deep::load is the part to check.
--- a/crates/engine/src/decode.rs 2026-10-20 07:43:17.564048661 +0300
+++ b/crates/engine/src/decode.rs 2026-10-20 07:43:17.580344955 +0300
@@ -74,17 +74,21 @@
impl Deep {
/// Takes `pic` when it is anything but plain 8-bit 4:2:0: `I010` (High 10),
- /// and the 4:2:2 shapes `I422` and `I210`, whose chroma is full height and is
+ /// the 4:2:2 shapes `I422` and `I210`, whose chroma is full height and is
/// averaged down a pair of rows to 4:2:0 as HEVC 4:2:2 is
- /// (`(a + b + 1) >> 1`). Into `wide` when `want_wide` and the picture is
+ /// (`(a + b + 1) >> 1`), and the 4:4:4 shapes `I444` and `I410`, averaged
+ /// down over 2x2 the same way. Into `wide` when `want_wide` and the picture is
/// above 8 bits, into `narrow` otherwise (`>> 2` for 10-bit); a plain
/// picture just clears [`Deep::on`].
pub(crate) fn load(&mut self, pic: &VideoFrame, want_wide: bool) {
use ec_core::frame::PixelFormat as F;
- let (bytes, full_height) = match pic.format {
- F::I010 => (2usize, false),
- F::I210 => (2, true),
- F::I422 => (1, true),
+ // (bytes per sample, chroma is full height, chroma is full width)
+ let (bytes, full_height, full_width) = match pic.format {
+ F::I010 => (2usize, false, false),
+ F::I210 => (2, true, false),
+ F::I422 => (1, true, false),
+ F::I410 => (2, true, true),
+ F::I444 => (1, true, true),
_ => {
self.on = false;
self.in_wide = false;
@@ -96,29 +100,39 @@
let (w, h) = (pic.width as usize, pic.height as usize);
let (cw, ch) = (w.div_ceil(2), h.div_ceil(2));
let src_ch = if full_height { h } else { ch };
- let dims = [(w, h, h), (cw, ch, src_ch), (cw, ch, src_ch)];
+ let src_cw = if full_width { w } else { cw };
+ let dims = [(w, h, h, w), (cw, ch, src_ch, src_cw), (cw, ch, src_ch, src_cw)];
let sample = |line: &[u8], x: usize| -> u32 {
if bytes == 2 { u32::from(u16::from_le_bytes([line[2 * x], line[2 * x + 1]])) } else { u32::from(line[x]) }
};
- // One output sample of row `r`: the row itself, or the average of the
- // pair of source rows under it for full-height chroma.
- let row_value = |plane: &ec_core::Plane, r: usize, rows_in: usize, pw: usize, x: usize, avg: bool| -> u32 {
- let line = |row: usize| &plane.data[row * plane.stride..row * plane.stride + pw * bytes];
- if avg {
+ // One output sample (r, x): the sample itself, or the rounded average of
+ // the 2x1 / 1x2 / 2x2 source samples under it for chroma stored at full
+ // height and/or width (`(a + b + 1) >> 1`, applied per axis).
+ let row_value = |plane: &ec_core::Plane, r: usize, rows_in: usize, cols_in: usize, x: usize, avg_v: bool, avg_h: bool| -> u32 {
+ let line = |row: usize| &plane.data[row * plane.stride..row * plane.stride + cols_in * bytes];
+ let at = |row: usize| -> u32 {
+ if avg_h {
+ let (a, b) = (2 * x, (2 * x + 1).min(cols_in - 1));
+ (sample(line(row), a) + sample(line(row), b) + 1) >> 1
+ } else {
+ sample(line(row), x)
+ }
+ };
+ if avg_v {
let (a, b) = (2 * r, (2 * r + 1).min(rows_in - 1));
- (sample(line(a), x) + sample(line(b), x) + 1) >> 1
+ (at(a) + at(b) + 1) >> 1
} else {
- sample(line(r), x)
+ at(r)
}
};
if self.in_wide {
self.wide.width = pic.width;
self.wide.height = pic.height;
let out = [&mut self.wide.y, &mut self.wide.u, &mut self.wide.v];
- for (i, ((plane, (pw, ph, rows_in)), out)) in pic.planes.iter().zip(dims).zip(out).enumerate() {
+ for (i, ((plane, (pw, ph, rows_in, cols_in)), out)) in pic.planes.iter().zip(dims).zip(out).enumerate() {
out.clear();
for r in 0..ph {
- out.extend((0..pw).map(|x| row_value(plane, r, rows_in, pw, x, full_height && i > 0) as u16));
+ out.extend((0..pw).map(|x| row_value(plane, r, rows_in, cols_in, x, full_height && i > 0, full_width && i > 0) as u16));
}
}
} else {
@@ -126,10 +140,10 @@
self.narrow.height = pic.height;
let shift = if bytes == 2 { 2 } else { 0 };
let out = [&mut self.narrow.y, &mut self.narrow.u, &mut self.narrow.v];
- for (i, ((plane, (pw, ph, rows_in)), out)) in pic.planes.iter().zip(dims).zip(out).enumerate() {
+ for (i, ((plane, (pw, ph, rows_in, cols_in)), out)) in pic.planes.iter().zip(dims).zip(out).enumerate() {
out.clear();
for r in 0..ph {
- out.extend((0..pw).map(|x| (row_value(plane, r, rows_in, pw, x, full_height && i > 0) >> shift) as u8));
+ out.extend((0..pw).map(|x| (row_value(plane, r, rows_in, cols_in, x, full_height && i > 0, full_width && i > 0) >> shift) as u8));
}
}
}
--- a/crates/engine/src/demux.rs 2026-10-20 07:43:17.564048661 +0300
+++ b/crates/engine/src/demux.rs 2026-10-20 07:43:17.583049239 +0300
@@ -4658,7 +4658,7 @@
/// [`hevc_refusal`]'s words, with the conversion.
fn avc_refusal(what: &str, profile: &str) -> crate::Error {
format!(
- "{what} is not supported — edith decodes 4:2:0 and 4:2:2 H.264 at 8 and 9/10 bits (High, High 10, High 4:2:2; progressive or interlaced) only ({profile}; convert to 4:2:0 8/10-bit with ffmpeg -pix_fmt yuv420p10le -c:v libx264 -profile:v high10)"
+ "{what} is not supported — edith decodes H.264 in 4:2:0, 4:2:2, 4:4:4 and monochrome at 8 and 9/10 bits (High, High 10, High 4:2:2, High 4:4:4 Predictive; progressive or interlaced) only ({profile}; convert to 4:2:0 8/10-bit with ffmpeg -pix_fmt yuv420p10le -c:v libx264 -profile:v high10)"
)
.into()
}
@@ -4679,16 +4679,12 @@
};
let (luma, chroma) = (sps.bit_depth_luma, sps.bit_depth_chroma);
let profile = format!("H.264 profile_idc {}", sps.profile_idc);
- // 4:2:0 and 4:2:2 are what `ec-h264` carries (the same two shapes as HEVC
- // here); monochrome, 4:4:4 and lossless are refused by name at every depth.
- match sps.chroma_format_idc {
- 0 => return Err(avc_refusal("H.264 4:0:0 (monochrome)", &profile)),
- 3 => return Err(avc_refusal("H.264 4:4:4", &profile)),
- _ => {}
- }
- if sps.transform_bypass {
- return Err(avc_refusal("lossless H.264 (qpprime_y_zero_transform_bypass)", &profile));
- }
+ // Every shape `ec-h264` decodes opens: 4:2:0, 4:2:2, 4:4:4 (also with
+ // separate colour planes), monochrome (handed over as 4:2:0 with neutral
+ // chroma) and lossless, at 8 and 9/10 bits. Chroma depth is only stated for
+ // streams that have chroma.
+ let has_chroma = sps.chroma_format_idc != 0 && !sps.separate_colour_plane;
+ let chroma = if has_chroma { chroma } else { luma };
if luma <= 8 && chroma <= 8 {
return Ok(8);
}
Limitations
- 11..14-bit only via
set_wide_samples; luma/chroma depth mismatch still refused; FMO/ASO/data partitioning still refused. - Lossless chroma DPCM and lossless deblocking protection are implemented from the spec text and verified only through x264 (4:2:0/4:2:2/4:4:4) vs ffmpeg; lossless 4:2:0/4:2:2 chroma edges are not snapshot-protected in the progressive deblocker.
- bS for 4:4:4 uses the luma coefficient flags only; matches ffmpeg on the vectors above.