camera-stream
A cross-platform Rust library for streaming frames from cameras. Currently supports macOS via AVFoundation, with a trait-based architecture designed for future platform backends.
Features
- Device discovery — enumerate cameras and query their supported formats (pixel format, size, frame rate ranges)
- Zero-copy frame delivery — frames are borrowed directly from the platform's pixel buffer within a callback scope
- Configurable streams — choose pixel format, size, and frame rate when opening a stream
- Platform-specific extensions — access advanced controls on macOS (focus, exposure, white balance, torch, zoom)
no_stdsupport — all core types and traits are available withoutstdoralloc; only the platform backends requirestd
Supported platforms
| Platform | Backend | Status |
|---|---|---|
| macOS | AVFoundation | ✅ |
| Linux | — | Planned |
| Windows | — | Planned |
Quick start
Add to your Cargo.toml:
[]
= "0.4"
Example: capture frames
use Arc;
use ;
use Duration;
use ;
use Frame;
use CameraStream;
use MacosCameraManager;
Run the included example with:
Architecture
The library is built around three core traits:
| Trait | Purpose |
|---|---|
CameraManager |
Discover devices and get the default camera |
CameraDevice |
Inspect supported formats and open a stream |
CameraStream |
Start/stop streaming with a frame callback |
Frames are delivered through the Frame trait, which provides access to pixel format, size, timestamp, and per-plane image data.
All traits use core::error::Error bounds rather than std::error::Error, so they are usable in no_std environments. Methods that enumerate devices or formats return impl Iterator rather than Vec, avoiding heap allocation in the trait interface.
Platform-specific extensions (macOS)
Import the MacosCameraDeviceExt trait from camera_stream::platform::macos::ext to access:
- Focus — query supported modes, set focus mode and point of interest
- Exposure — set mode, point of interest, and target bias
- White balance — set mode
- Torch — check availability and set mode
- Zoom — query max factor and set zoom level
- Frame duration — set min/max video frame duration on the active format
All mutating operations acquire an AVCaptureDevice configuration lock automatically.
Error handling
Platform errors preserve the native error objects (e.g. NSError on macOS) rather than eagerly converting to strings. Use Display (or to_string()) to get a human-readable description on demand.
Pixel formats
| Variant | Description |
|---|---|
Nv12 |
YCbCr 4:2:0 biplanar (common macOS default) |
Yuyv |
YCbCr 4:2:2 packed |
Uyvy |
YCbCr 4:2:2 packed (alternate byte order) |
Bgra32 |
32-bit BGRA |
Jpeg |
JPEG compressed |
Feature flags
| Feature | Default | Description |
|---|---|---|
std |
✅ | Enables platform backends (macOS AVFoundation, etc.) |
Without std, all core types, traits (CameraManager, CameraDevice, CameraStream, Frame), and error types are still available — only the concrete platform implementations require std.
Minimum Rust version
1.85 (edition 2024)
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.