Skip to content

Decode 4:4:0 sources as 4:4:4, not 4:2:2 (task #100) - #258

Merged
StuartCameronCode merged 4 commits into
mainfrom
stuart/100-4-4-0-sources-yuv440p-yuvj440p-from-jpeg
Nov 22, 2026
Merged

StuartCameronCode merged 4 commits into
mainfrom
stuart/100-4-4-0-sources-yuv440p-yuvj440p-from-jpeg

Conversation

@StuartCameronCode

Copy link
Copy Markdown
Owner

Problem

pixel_format::classify put the subsampling code 440 in the 4:2:2 class, so the decoder ffmpeg converted 4:4:0 sources (yuv440p, and yuvj440p from some JPEG/MJPEG cameras) to yuv422p*. 4:4:0 has full horizontal chroma and half vertical, and 4:2:2 is the other way round, so this halved the source's horizontal chroma before VapourSynth saw it. That breaks the module's rule of never piping less chroma on either axis. On a fixture with 1-px colour columns, the stripes disappeared (mean error 70 levels).

Change

  • 440 now falls through to the 4:4:4 class, so a 4:4:0 source pipes as yuv444p / yuv444p10le / …12le / …16le. 4:1:0 and 4:1:1 still go to 4:2:2, which is a true superset of them.
  • The Dart twin pixelFormatChromaLayout moves 440 to c444. The warnings checked against the worker's tables (NVENC/hardware, ProRes, v210, AV1) gained yuv440p rows, and the Rust and Dart tables still agree.
  • New property test pipe_format_never_has_less_chroma_on_either_axis: it checks every planar code × prefix (yuv/yuvj/yuva) × depth through chroma_grid (from [SUGGESTION] pre-treatment video analisys/measurements #97), and it fails on the old mapping.
  • Behaviour change: "Match source" output from a 4:4:0 source is now 4:4:4. A 4:4:0 source is piped as 4:4:4, so it needs no grid padding from [SUGGESTION] pre-treatment video analisys/measurements #97 at any size. The pipe and the passes carry about 1.5× the bytes for these sources.
  • Docs: the CLAUDE.md "Source Pixel Formats" rule, the README source formats row, an ENGINEERING_NOTES entry, and the report docs/reports/task-100-440-sources (with its measurement script).

Range

A full-range 4:4:0 source keeps full range. With the bundled FFmpeg 9, black decodes to 0, not 16, as yuv444p, both from yuv440p tagged pc and from MJPEG yuvj. FFmpeg 9 carries range as a frame property, so the yuvj → yuv name change is only a label, as it already was with the old yuv422p mapping.

Testing

  • cargo test: passes in full (lib 678 plus every integration test), after merging main.
  • Dart unit tests (pixel_format, hardware warning, AV1, v210, ProRes, off-grid before frame, pipe_source order): pass.
  • Heavy group 4:4:0 sources keep their horizontal chroma (task #100): passes 4/4. Each encode was compared sample for sample with ffmpeg's own 4:4:4 decode of the same source. It covers 8-bit, 10-bit, full range and the odd size 127x95, and 0 samples differ. Preview vs encode is 0.000.
  • Heavy integration_off_grid_source_test (task [SUGGESTION] pre-treatment video analisys/measurements #97): passes 9/9.

🤖 Generated with Claude Code

StuartCameronCode and others added 4 commits November 22, 2026 13:56
The pipe-format classifier put the subsampling code 440 with 4:2:2,
judging one axis. 4:4:0 (some JPEG/MJPEG cameras record yuvj440p) has
full horizontal chroma and half vertical, so the decoder's
-pix_fmt yuv422p halved its horizontal chroma. 1-px colour columns came
through 70 levels off on average (the columns gone); testsrc2 1.78/21
against a one-step 4:4:4 rendering. Through 4:4:4: 0/0.

- pixel_format.rs: 440 is C444; 4:1:0 stays C422. New property test
  pipe_format_never_has_less_chroma_on_either_axis over every planar YUV
  code x prefix x depth.
- The Dart twin pixelFormatChromaLayout moves 440 to c444, so the ProRes,
  v210, AV1 and NVENC warnings describe what the worker does; yuv440p rows
  added to the tables pinned between Rust and Dart.
- Heavy group "4:4:0 sources keep their horizontal chroma (task #100)":
  the encode is bit-identical to ffmpeg's own 4:4:4 decode and keeps the
  columns, at 8/10-bit, full range and 127x95; it failed on the old
  worker (4:2:2 output, columns gone, 127x95 "BlankClip: invalid width").
- Report docs/reports/task-100-440-sources, engineering note, CLAUDE.md,
  README, reports index.

Output change: under Color Format "Match source" a 4:4:0 source now comes
out 4:4:4 at its depth (x264: High 4:4:4 Predictive) where it was 4:2:2.
Explicit formats, AV1, ProRes, v210 and HuffYUV now convert from the true
chroma; ProRes 422/v210 warnings now say the chroma is reduced, and
ProRes 4444 no longer says it pads. Pipe and passes carry ~1.5x the bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts in docs/reports/README.md and docs/ENGINEERING_NOTES.md were
additive (task #97/#98 rows and notes beside #100's). The 4:4:0 property
test now takes each format's subsampling from task #97's chroma_grid
instead of a duplicate table in the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ces-yuv440p-yuvj440p-from-jpeg

# Conflicts:
#	docs/ENGINEERING_NOTES.md
…ces-yuv440p-yuvj440p-from-jpeg

# Conflicts:
#	docs/reports/README.md
@StuartCameronCode
StuartCameronCode merged commit 7bb59ca into main Nov 22, 2026
12 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant