Skip to content

Fix webcam MJPEG negotiation for screen recordings - #8792

Open
ottosilva wants to merge 2 commits into
omacom:quattrofrom
ottosilva:fix/webcam-capture-negotiation
Open

ottosilva wants to merge 2 commits into
omacom:quattrofrom
ottosilva:fix/webcam-capture-negotiation

Conversation

@ottosilva

Copy link
Copy Markdown

Fixes #7300

Summary

  • prefer MJPEG only when the selected webcam resolution supports the 30 fps target
  • preserve V4L2 format autodetection when MJPEG is unsupported or capability probing fails
  • require exact FourCC and resolution matches to avoid forcing unsupported capture tuples

Test plan

  • bash -n bin/omarchy-capture-screenrecording test/shell.d/screenrecording-test.sh
  • git diff --check
  • bash test/shell.d/screenrecording-test.sh (30 consecutive runs)
  • Hardware recording verification (no accessible webcam device in the current environment)

./test/all reached and passed the screen-recording tests. Seven unrelated test files failed because this checkout lacks external fixtures/services or cannot write to system/user paths in the restricted environment.

Copilot AI balanced review requested due to automatic review settings August 28, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates webcam capture negotiation to prefer MJPEG when the selected resolution supports 30 fps.

Changes:

  • Parses V4L2 capabilities for matching MJPEG modes.
  • Adds MJPEG and fallback negotiation tests.
  • Preserves automatic format selection when probing fails.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
bin/omarchy-capture-screenrecording Adds MJPEG capability negotiation.
test/shell.d/screenrecording-test.sh Tests supported modes and fallbacks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@btsouth

btsouth commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Tested this branch's negotiation logic on real hardware and it fixes the problem.

Lenovo Performance Camera (uvcvideo) on 4.0.0.r1849. Same shape as the issue: MJPG offers 1280x720 at 30fps, YUYV caps 720p at 10fps, and this camera has no 640x360 mode at all, so the resolution loop lands on 1280x720. Checked with v4l2-ctl --get-fmt-video and --get-parm while the overlay had the device open:

stock:       YUYV 1280x720 at 10fps
this branch: MJPG 1280x720 at 30fps

Also ran a full recording with the patched negotiation. The overlay is smooth and the output is clean 60fps CFR with audio in sync. One note on the parser: the tests stub v4l2-ctl output with space indentation, but I ran the awk against the real tab-indented output from this camera and it matched fine.

@ahmadtv

ahmadtv commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Hardware data point from an iMac18,3 (FaceTime HD camera, uvcvideo), on Omarchy 4.0.3 without this PR: while the webcam overlay runs, v4l2-ctl --get-fmt-video / --get-parm report YUYV 1280x720 at 10.000 fps. This camera's raw mode tops out at 10 fps at 720p. With input_format=mjpeg added to the overlay's demuxer options, the same camera runs MJPG at 29.970 fps.

It shows in the recording too: with the 10 fps YUYV overlay up, gpu-screen-recorder dropped to 55 fps here, so the video played back fast (-fm cfr stamps every frame 1/60 s apart). With MJPEG it stayed at 58.

I haven't run this branch itself yet; happy to, if a hardware check helps it land. (#9306 covers the same ground.)

@omarchybot omarchybot added bug Something isn't working compatibility Make Omarchy work better on everything! labels Sep 27, 2026
Both this branch and omacom#8374 appended tests to the end of screenrecording-test.sh. The resolution keeps both blocks, quattro's first and this branch's webcam negotiation tests after it.

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

Copy link
Copy Markdown
Collaborator

Reviewed by Claude Opus 5.5. The configured second opinion (Codex Medium) did not run on this pull request: it answered a ping, but its daily review budget was already spent, so this review is one model's reading.

Merged quattro into the branch (ec6e6cf). The branch conflicted with #8374, which also appended tests to the end of test/shell.d/screenrecording-test.sh. The merge keeps both blocks, quattro's first and this branch's after it, and changes nothing in bin/omarchy-capture-screenrecording, which merged cleanly. It now merges cleanly.

What was checked, on a disposable Omarchy VM:

  • test/shell.d/screenrecording-test.sh at the merged head: 32 passed, 0 failed.
  • The same tests against quattro's script, with the extraction pointed at start_webcam_overlay: the screenrecord --with-webcam: overlay locks to YUYV @5fps instead of MJPG @30fps at 1280x720 #7300 case fails (video_size=1280x720,framerate=30 with no input_format, so YUYV is left to win). That is the bug as reported, and since the merge leaves the script as this branch's change on top of quattro, it is also the fix reverted.
  • webcam_mjpeg_supports_framerate against tab-indented --list-formats-ext output in the real layout (YUYV listed first at 10 fps, MJPG at 30): it matches 1280x720 at 30, and rejects 640x360 (not offered) and 60 fps (not offered). 29.970 fps intervals fall inside the 0.05 tolerance, which the branch's own test covers.
  • ./test/cli: one failure, vscode generated theme references current theme file, which fails identically on quattro and is unrelated.

The change is proportionate: one parser and one extra option, leaving autodetection alone whenever MJPEG cannot do 30 fps at the chosen size or probing returns nothing. Nothing wrong was found.

What it waits on. This is a hardware fix, and a stubbed v4l2-ctl proves only that the parser does what the author believes the camera reports. It needs confirming on a real camera, against the full head commit ec6e6cf. #7300 was opened by the author of this pull request, so that confirmation has to come from a maintainer. @btsouth's report on e3782a5 (MJPG 1280x720 at 30 fps on a Lenovo Performance Camera) and @ahmadtv's iMac data point are good supporting evidence, but they predate this head and come from neither of those accounts. To check, on a machine whose camera offers MJPG:

curl -fsSL https://raw.githubusercontent.com/ottosilva/omarchy/ec6e6cf281b9986623b27c5830e6706046580e89/bin/omarchy-capture-screenrecording -o /tmp/screenrecording-8792
bash /tmp/screenrecording-8792 --with-webcam --fullscreen
v4l2-ctl -d /dev/video0 --get-fmt-video --get-parm   # while recording: expect MJPG at 30 fps
bash /tmp/screenrecording-8792 --stop-recording

Related: #13373 addresses a different cause of a slow webcam (the auto-exposure priority control stretching frames in dim light) and complements this rather than competing with it. #9306 made the same change and was closed as a duplicate of this one.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds webcam format negotiation to screen recording capture.

The PR appears safe to merge based on the reviewed code and tests.

Summary

The PR adds a capability check before requesting MJPEG for the screen-recording webcam overlay.

  • It requests MJPEG only when the selected resolution advertises a near-30 fps MJPEG interval; otherwise it retains format autodetection.
  • It adds shell tests for supported and unsupported modes, exact matching, near-30 fps, and failed capability probing.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Probe webcam formats] --> B[Select preferred resolution]
  B --> C{MJPEG at selected size and near 30 fps?}
  C -->|Yes| D[Request MJPEG from mpv]
  C -->|No| E[Keep format autodetection]
Loading

Reviews (1) · Last reviewed commit: "Merge quattro to resolve the screen-reco..."

@ottosilva

Copy link
Copy Markdown
Author

@btsouth @ahmadtv thanks again for the earlier hardware checks, they were really useful.

omarchybot merged quattro into the branch, so the head is now ec6e6cf and your results predate it. If either of you has a couple of minutes, could you re-run the check at this exact head? These are the commands from the review above:

curl -fsSL https://raw.githubusercontent.com/ottosilva/omarchy/ec6e6cf281b9986623b27c5830e6706046580e89/bin/omarchy-capture-screenrecording -o /tmp/screenrecording-8792
bash /tmp/screenrecording-8792 --with-webcam --fullscreen
v4l2-ctl -d /dev/video0 --get-fmt-video --get-parm   # while recording: expect MJPG at 30 fps
bash /tmp/screenrecording-8792 --stop-recording

Adjust /dev/video0 if your camera is on another node. Posting the v4l2-ctl output, your camera model, and the commit you tested would be perfect. No pressure if you don't have time.

@omarchybot

Copy link
Copy Markdown
Collaborator

The second opinion that could not run on the last review has now run. Codex Medium reviewed the head, ec6e6cf, against quattro and found no defect in the change. It agreed that the cause is real (lavf picks the pixel format before it asks for the frame rate, so framerate=30 alone lets the driver settle on YUYV at 10 fps) and that the diff is the size the problem warrants. It reached the same conclusion as the earlier review, and since it can read that review, its agreement is not independent proof. The code has not changed since then, so the worker results in the review above still stand.

It raised two points that are not defects but are worth knowing before this merges:

  • A camera that already does 30 fps in YUYV at the chosen size will also be switched to MJPEG if MJPEG offers 30 fps there, which the description says is intended. A camera that advertises MJPEG but delivers it badly would lose its overlay, because nothing falls back to autodetection. Only real hardware can rule that out.
  • The last test, "preserves fallback options when capability probing fails", feeds v4l2-ctl empty output rather than a failing command. The script discards stderr, so the two behave the same and this needs no change.

What it waits on. Confirmation on a real camera at ec6e6cf, as described in the review above. Re-runs from @btsouth and @ahmadtv at this head are welcome and help the maintainer decide. But #7300 was opened by this pull request's author, so the confirmation that lets it be marked verified has to come from a maintainer.

@phil-bowens

Copy link
Copy Markdown

Re-ran the check at ec6e6cf on two machines.

Desktop: Logitech C920 (046d:08e5, uvcvideo), Omarchy 4.0.4. --with-webcam --fullscreen, read while recording:

Width/Height      : 640/360
Pixel Format      : 'MJPG' (Motion-JPEG)
Frames per second: 30.000 (30/1)

The recording is 60 fps CFR, and the overlay stopped cleanly. Streamed directly in that mode, the camera delivers 30.0 fps.

Laptop: Dell Inspiron 3501, integrated Microdia camera (0c45:671e, uvcvideo), Omarchy 4.0.4. Same result: MJPG 640x360 at 30 fps while recording, a 60 fps CFR recording, a clean stop, and 30.0 fps when streamed directly. Its raw 720p mode only reaches 10 fps (the #7300 split), but it also lists raw 640x360 at 30, so the loop picks 360p.

It works as described on both. One caveat for whoever marks this verified: both cameras list 640x360, so the loop stops there, and neither one exercises the #7300 case (no 360p mode, so 720p is chosen). @btsouth's Lenovo has that shape.

On the second review's point about cameras that already do 30 fps raw: both of these do (YUYV 640x360 at 30), so here the change is YUYV 360p → MJPG 360p at the same size. Overlay mpv CPU, one 30 s round each: stock (YUYV) 3.9% vs this head (MJPG) 5.8% on the desktop (i7-7700), and 3.8% vs 4.3% on the laptop (i5-1135G7). If that's worth avoiding, phil-bowens:raw-first-on-8792 has a commit on top of ec6e6cf that asks for MJPEG only when raw at the chosen size can't reach 30 fps. A #7300-shaped camera still gets MJPEG, and the tests use both cameras' real format lists. It's optional and doesn't affect this head's verification.

Tested with Claude Code; I checked the results on both machines myself.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed by Claude Opus 5.5, with Codex Medium as the second opinion. The head is still ec6e6cf, so the worker results and reviews above still stand. This pass read @phil-bowens's report.

Both cameras ran MJPG 640x360 at 30 fps at this head, as expected. Both reviewers read it the same way: this is good evidence that the change does no harm on common cameras, but it does not exercise #7300. Both cameras list 640x360, so the resolution loop stops there. #7300's case is a camera with no 640x360 mode, where 1280x720 is chosen and its raw mode drops to 5-10 fps. The confirmation that lets this be marked verified also has to come from a maintainer, since #7300 was opened by this pull request's author. Neither of those is a fault in the report.

The commit on phil-bowens:raw-first-on-8792 keeps the raw mode whenever it reaches 30 fps at the chosen size, and still asks for MJPEG in the #7300 case. It is a trade-off rather than a fix for a defect in this head: about 0.5 to 2 points less CPU on cameras that were never broken, and their behaviour stays exactly as before, in exchange for a second parser path and the question of which raw format FFmpeg actually picks when several are listed. Whether to take it is the maintainer's call. It is not part of this pull request.

What it waits on. A maintainer's check at ec6e6cf, ideally on a camera without a 640x360 mode, using the commands in the first review above, and a decision on the raw-first follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working compatibility Make Omarchy work better on everything!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

screenrecord --with-webcam: overlay locks to YUYV @5fps instead of MJPG @30fps at 1280x720

6 participants