fix(screen_recorder): record the screen, not the webcam, on macOS - #484
Open
hubooy wants to merge 1 commit into
Open
fix(screen_recorder): record the screen, not the webcam, on macOS#484hubooy wants to merge 1 commit into
hubooy wants to merge 1 commit into
Conversation
avfoundation enumerates cameras before screens, so passing screen_index straight through to -i selects device 0 — the built-in camera on any Mac that has one. The tool then silently records the user's face while the caller believes it is capturing the screen, with no error to reveal it. That is a privacy problem as much as a correctness one: screen_capture_selector advertises this tool as "no webcam" (and routes webcam overlay work to cap_recorder), and screen_index is documented as a monitor index, not a device index. The Windows and Linux branches do not take screen_index at all, so the mac branch was the only one leaking a platform device numbering into a cross-platform parameter. Map the monitor index to its real avfoundation device index by parsing -list_devices, falling back to the raw index when detection fails. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GYThSL15CujvBwD1wuUmr9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On macOS,
screen_recorderrecords the webcam instead of the screen on any Mac that has a camera.avfoundation enumerates cameras before screens, so device
0is the built-in camera._build_mac_cmdpassedscreen_indexstraight through to-i, so the defaultscreen_index=0selects the camera. There is no error — the recording simply contains the operator's face instead of their screen, and the caller has no signal that anything went wrong.This reads as a privacy issue as much as a correctness one: the tool opens the camera and records the person while they believe they are capturing a screen.
It is unambiguously unintended:
screen_capture_selector.py:4-5advertises this tool as "no webcam", and lists "No webcam overlay (picture-in-picture)" as one of its limitations (:185), routing webcam work tocap_recorderinstead.screen_indexschema documents it as "Monitor index for multi-monitor setups (0 = primary)" — a monitor index, not a device index._build_windows_cmdand_build_linux_cmddo not takescreen_indexat all (gdigrab grabs the desktop; x11grab uses$DISPLAY). The mac branch was the only one leaking a platform's device numbering into a cross-platform parameter.regioncropping on macOS happens in post using screen geometry, which cannot work against a 1280x720 camera frame.Related issue
None — filing the fix directly.
Changes
_detect_screen_device_mac(), which parsesffmpeg -f avfoundation -list_devicesand maps a monitor index to its real avfoundation device index._build_mac_cmduses the resolved device, falling back to the rawscreen_indexwhen detection fails, so behavior is never worse than today.Testing
python -m pytest tests/contracts/ -q— 630 passed, 7 skipped.Device mapping verified on macOS 15 (Darwin 25.5.0).
ffmpeg -f avfoundation -list_devices true -i ""on this machine lists:So the default
screen_index=0selected the FaceTime camera — three camera devices are enumerated before the only screen._detect_screen_device_mac(0)returns3, the actual screen.Fallback path:
_detect_screen_device_mac(1)and(9)returnNoneon this single-monitor machine, so_build_mac_cmdfalls back to the raw index — i.e. today's behavior — instead of failing.Not verified: I did not capture a recording as part of this PR, and I have no Windows or Linux machine to check; those two branches are untouched by the diff.
Checklist
make test-contracts/make test) where applicable.screen_indexsemantics.🤖 Generated with Claude Code
https://claude.ai/code/session_01GYThSL15CujvBwD1wuUmr9