Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
ScreenCaptureKit-rs
Safe, idiomatic Rust bindings for macOS ScreenCaptureKit framework.
Capture screen content, windows, and applications with high performance and low overhead on macOS 12.3+.
โจ Features
- ๐ฅ Screen & Window Capture - Capture displays, windows, or specific applications
- ๐ Audio Capture - Capture system audio and microphone input
- โก Real-time Processing - High-performance frame callbacks with custom dispatch queues
- ๐๏ธ Builder Pattern API - Clean, type-safe configuration with
::build() - ๐ Async Support - Runtime-agnostic async API (works with Tokio, async-std, smol, etc.)
- ๐จ IOSurface Access - Zero-copy GPU texture access for Metal/OpenGL
- ๐ก๏ธ Memory Safe - Proper reference counting and leak-free by design
- ๐ฆ Zero Dependencies - No runtime dependencies (only dev dependencies for examples)
๐ฆ Installation
Add to your Cargo.toml:
[]
= "1.0"
For async support:
[]
= { = "1.0", = ["async"] }
For latest macOS features:
[]
= { = "1.0", = ["macos_15_0"] }
๐ Quick Start
Basic Screen Capture
use *;
;
Async Capture
use ;
use *;
async
Window Capture with Audio
use *;
๐ฏ Key Concepts
Builder Pattern
All types use a consistent builder pattern with a final .build() call:
// Content filters
let filter = build
.display
.exclude_windows
.build;
// Stream configuration
let config = builder
.width
.height
.pixel_format
.captures_audio
.build;
// Options for content retrieval
let content = with_options
.on_screen_windows_only
.exclude_desktop_windows
.get?;
Custom Dispatch Queues
Control callback threading with custom dispatch queues:
use ;
let queue = new;
stream.add_output_handler_with_queue;
QoS Levels:
Background- Maintenance tasksUtility- Long-running tasksDefault- Standard priorityUserInitiated- User-initiated tasksUserInteractive- UI updates (highest priority)
IOSurface Access
Zero-copy GPU texture access:
๐๏ธ Feature Flags
Core Features
| Feature | Description |
|---|---|
async |
Runtime-agnostic async API (works with any executor) |
macOS Version Features
Feature flags enable APIs for specific macOS versions. They are cumulative (enabling macos_15_0 enables all earlier versions).
| Feature | macOS | APIs Enabled |
|---|---|---|
macos_13_0 |
13.0 Ventura | Opacity configuration |
macos_14_0 |
14.0 Sonoma | Content picker, clipboard ignore, shadow displays |
macos_14_2 |
14.2 | Capture fractions, shadow control, child windows |
macos_14_4 |
14.4 | Future features |
macos_15_0 |
15.0 Sequoia | Recording output, HDR capture |
Version-Specific Example
let config = builder
.width
.height
.should_be_opaque // macOS 13.0+
.ignores_shadows_single_window // macOS 14.2+
.includes_child_windows // macOS 14.2+
.build;
๐ API Overview
Core Types
SCShareableContent- Query available displays, windows, and applicationsSCContentFilter- Define what to capture (display/window/app)SCStreamConfiguration- Configure resolution, format, audio, etc.SCStream- Main capture stream with output handlersCMSampleBuffer- Frame data with timing and metadata
Async API (requires async feature)
AsyncSCShareableContent- Async content queriesAsyncSCStream- Async stream with frame iteration
Display & Window Types
SCDisplay- Display information (resolution, ID, etc.)SCWindow- Window information (title, bounds, owner, etc.)SCRunningApplication- Application information (name, PID, etc.)
Media Types
CMSampleBuffer- Sample buffer with timing and attachmentsCMTime- High-precision timestampsIOSurface- GPU-backed pixel buffersCGImage- CoreGraphics images
Configuration Types
PixelFormat- BGRA, YCbCr420v, YCbCr420f, l10r (10-bit)SCPresenterOverlayAlertSetting- Privacy alert behaviorSCCaptureDynamicRange- HDR/SDR modes (macOS 15.0+)
๐ Examples
The examples/ directory contains focused API demonstrations:
Quick Start (Numbered by Complexity)
01_basic_capture.rs- Simplest screen capture02_window_capture.rs- Capture specific windows03_audio_capture.rs- Audio + video capture04_pixel_access.rs- Read pixel data withstd::io::Cursor05_screenshot.rs- Single screenshot (macOS 14.0+)06_iosurface.rs- Zero-copy GPU buffers07_list_content.rs- List available content08_async.rs- Async/await API with multiple examples09_closure_handlers.rs- Closure-based handlers and delegates10_recording_output.rs- Direct video file recording (macOS 15.0+)11_content_picker.rs- System UI for content selection (macOS 14.0+)
See examples/README.md for detailed descriptions.
Run an example:
# Basic examples
# Feature-gated examples
๐งช Testing
Run Tests
# All tests
# With features
# Specific test
Linting
๐๏ธ Architecture
Module Organization
screencapturekit/
โโโ cm/ # Core Media (CMSampleBuffer, CMTime, CVPixelBuffer)
โโโ cg/ # Core Graphics (CGRect, CGImage)
โโโ stream/ # Stream management
โ โโโ configuration/ # SCStreamConfiguration
โ โโโ content_filter/ # SCContentFilter
โ โโโ sc_stream/ # SCStream
โโโ shareable_content/ # SCShareableContent, SCDisplay, SCWindow
โโโ output/ # Frame buffers and pixel data
โโโ dispatch_queue/ # Custom dispatch queues
โโโ error/ # Error types
โโโ screenshot_manager/ # SCScreenshotManager (macOS 14.0+)
โโโ content_sharing_picker/ # SCContentSharingPicker (macOS 14.0+)
โโโ recording_output/ # SCRecordingOutput (macOS 15.0+)
โโโ async_api/ # Async wrappers (feature = "async")
โโโ utils/ # FFI strings, FourCharCode utilities
โโโ prelude/ # Convenience re-exports
Memory Management
- Reference Counting - Proper CFRetain/CFRelease for all CoreFoundation types
- RAII - Automatic cleanup in Drop implementations
- Thread Safety - Safe to share across threads (where supported)
- Leak Free - Comprehensive leak tests ensure no memory leaks
๐ง Platform Requirements
- macOS 12.3+ (Monterey) - Base ScreenCaptureKit support
- macOS 13.0+ (Ventura) - Additional features with
macos_13_0 - macOS 14.0+ (Sonoma) - Content picker, advanced config
- macOS 15.0+ (Sequoia) - Recording output, HDR capture
๐ค Contributing
Contributions welcome! Please:
- Follow existing code patterns (builder pattern with
::build()) - Add tests for new functionality
- Run
cargo testandcargo clippy - Update documentation
๐ฅ Contributors
Thanks to everyone who has contributed to this project!
- Per Johansson - Maintainer
- Iason Paraskevopoulos
- Kris Krolak
- Tokuhiro Matsuno
- Pranav Joglekar
- Alex Jiao
- Charles
- bigduu
๐ License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.