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 — core types (PixelFormat,Size,FrameRate,Frametrait) are available withoutstd; usedefault-features = falseand optionally enable theallocfeature
Supported platforms
| Platform | Backend | Status |
|---|---|---|
| macOS | AVFoundation | ✅ |
| Linux | — | Planned |
| Windows | — | Planned |
Quick start
Add to your Cargo.toml:
[]
= "0.1"
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.
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 rate — change active frame rate on a running device
All mutating operations acquire an AVCaptureDevice configuration lock automatically.
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 device/stream/error types (implies alloc) |
alloc |
via std |
Enables FormatDescriptor and Vec-based APIs |
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.