Skip to content

perf(recording): capture X11 frames through MIT-SHM - #2501

Closed
yashranaway wants to merge 2 commits into
CapSoftware:mainfrom
yashranaway:perf/x11-shm-capture
Closed

yashranaway wants to merge 2 commits into
CapSoftware:mainfrom
yashranaway:perf/x11-shm-capture

Conversation

@yashranaway

@yashranaway yashranaway commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

on x11 every captured frame came back through the x socket as one big image reply. that's about 23ms of cpu per 1080p frame here, so recording couldn't hold 60fps at 1080p or 30fps at 1440p. now the grabber keeps one shared memory segment the x server writes each frame into, the same way ffmpeg's x11grab and obs do it.

remote x or a server without shared memory falls back to the old path, and so does a shared read that ever fails. under xvfb a 1080p frame drops from about 25ms to 3.5ms and 1440p from 55ms to 8ms.

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with no outstanding findings.

Summary

The PR adds shared-memory X11 capture and keeps GetImage as a fallback.

  • Linux X11 capture can read frames through shared memory.

Reviews (2) · Last reviewed commit: "test(recording): run X11 capture tests o..." · Reviewed by Greptile

X11Grabber requested every frame with GetImage, so each frame streamed
through the X socket into a reply buffer before being copied into the
FFmpeg frame. It now keeps one MIT-SHM 1.2 segment the server writes
into with ShmGetImage, grows it when a captured window grows, and falls
back to GetImage when the server has no shared memory or a shared read
fails. A display test compares both paths byte for byte for a screen
and a resized window, and skips without DISPLAY.
@yashranaway

Copy link
Copy Markdown
Contributor Author

@greptileai review

@vercel

vercel Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

@yashranaway is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread crates/recording/src/sources/screen_capture/linux.rs
Comment thread crates/recording/src/sources/screen_capture/linux.rs Outdated
The capture test painted the root window of whatever DISPLAY pointed at, which on a developer machine is the live desktop. It and the benchmark now read CAP_TEST_X11_DISPLAY and skip without it. Also drops two comments that only restated what the code does.
@yashranaway

Copy link
Copy Markdown
Contributor Author

@greptileai review

@richiemcilroy

Copy link
Copy Markdown
Member

Thanks for this! #2551 takes the same MIT-SHM approach and has now merged: it retries a failed ShmGetImage with GetImage for that frame instead of turning SHM off for the session, detaches its segments on drop, and its tests run in CI. Your memfd-based segment creation (no leak on crash, works across Flatpak/container IPC boundaries) would be a great follow-up on top of #2551 if you're interested.

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.

2 participants