Skip to content

Decode V4L2 cameras with the YCbCr encoding they report - #25

Merged
dhh merged 3 commits into
masterfrom
fix-v4l2-color-matrix
Nov 12, 2026
Merged

dhh merged 3 commits into
masterfrom
fix-v4l2-color-matrix

Conversation

@dhh

@dhh dhh commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Qt Multimedia's V4L2 camera only reads the colorspace field and maps V4L2_COLORSPACE_SRGB to BT.601 (the source even carries a ##### is this correct??? comment). It never looks at ycbcr_enc. The Elgato Cam Link 4K reports sRGB with an explicit BT.709 encoding, so Monologue decoded it with the BT.601 matrix and colors came out muted next to Zoom/Chromium, which honor the encoding.

On the first frame, Monologue now asks the device (VIDIOC_G_FMT) for its YCbCr encoding. When Qt guessed BT.601 but the driver says BT.709/BT.2020, frames are retagged with the right color space, so both preview and recordings decode correctly. Devices that really are BT.601 (e.g. the Logi 4K Pro's MJPEG) are untouched.

The frame-wrapping buffer used by the writer moved into mediautils with a format override, so both places share it. When the writer converts packed 4:2:2 to 4:2:0 for the encoder (#32), it keeps the corrected label, so a Cam Link recording is tagged BT.709. A test records relabelled YUYV frames and checks the file with ffprobe.

🤖 Generated with Claude Code

Qt Multimedia's V4L2 camera maps V4L2_COLORSPACE_SRGB to BT.601 and never
reads ycbcr_enc. Capture cards such as the Elgato Cam Link 4K report sRGB
with an explicit BT.709 encoding, so Monologue decoded them with the wrong
matrix: colors came out muted compared to browsers and other apps.

Ask the device for its encoding on the first frame and, when Qt guessed
BT.601 but the driver says otherwise, retag frames with the correct color
space. Preview and recordings both use the corrected frames. Cameras that
really deliver BT.601 (like most MJPEG webcams) are untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain.

Summary

The PR reads the camera’s reported YCbCr encoding and corrects frames that Qt marked as BT.601.

  • Camera previews and recordings use the color space reported by V4L2.

The earlier timestamp finding is fixed: withFormat copies both source timestamps. No new actionable issues were found. Tests were not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Camera[Camera frame] --> Check{Qt reports BT.601?}
  Driver[Reported YCbCr encoding] --> Check
  Check -->|Different supported encoding| Wrap[Correct label and keep capture times]
  Check -->|No correction needed| Frame[Keep frame]
  Wrap --> Preview[Preview]
  Wrap --> Writer[Writer]
  Frame --> Preview
  Frame --> Writer
  Writer --> Convert[Preserve packed YUV color labels]
  Convert --> MP4[H.264 MP4]
Loading

Reviews (3) · Last reviewed commit: "Merge master into fix-v4l2-color-matrix" · Reviewed by Greptile

Comment thread src/backend.cpp Resolved
dhh and others added 2 commits November 10, 2026 18:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Master's writer now converts frames to 4:2:0; its plain copy for other
formats uses media::withFormat from this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhh
dhh merged commit 270ab86 into master Nov 12, 2026
2 checks passed
@dhh
dhh deleted the fix-v4l2-color-matrix branch November 12, 2026 15:36
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