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.
cameras enumerates cameras, probes their supported formats, opens a streaming session, and delivers frames. It runs on macOS (AVFoundation), Windows (Media Foundation), and Linux (V4L2) with the same API on each platform.
The public surface is plain data types (Device, Capabilities, FormatDescriptor, StreamConfig, Frame) and a handful of free functions. There are no trait objects in the public API, no hidden global state, and no unsafe required of consumers.
Quick Start
Add this to your Cargo.toml:
[]
= "0.1"
And in main.rs:
use Duration;
Dropping the Camera stops the stream. Dropping the DeviceMonitor joins its worker.
Platform Support
| Platform | USB / Built-in | RTSP (rtsp feature) |
|---|---|---|
| macOS | AVFoundation (via objc2) |
retina + VideoToolbox (H.264 / H.265 / MJPEG) |
| Windows | Media Foundation (via windows) |
retina + Media Foundation (H.264 / H.265 / MJPEG) |
| Linux | V4L2 mmap streaming (via v4l) |
not supported |
API Overview
Enumerate and probe:
let devices = devices?;
let capabilities = probe?;
Open a camera and read frames:
use Duration;
let camera = open?;
let frame = next_frame?;
Convert pixel formats (BGRA8, RGBA8, YUYV, NV12, MJPEG via zune-jpeg):
let rgb = to_rgb8?;
let rgba = to_rgba8?;
Watch for camera hotplug:
use Duration;
let monitor = monitor?;
while let Ok = next_event
Pick a fallback format if the exact request is not supported:
let picked = best_format.expect;
Higher-level primitives
Two optional modules layer on top of the core. They are pure conveniences; callers who want full control can stay on open and next_frame.
cameras::source: one enum for USB and RTSP
CameraSource lets UIs and configs carry a single "where do frames come from" value instead of branching between open and open_rtsp at every call site.
use ;
CameraSource implements PartialEq, Eq, and Hash (USB compared by device id, RTSP by URL plus credentials) so it works as a map key or a Signal value.
cameras::pump: background frame pump with pause and snapshot
pump::spawn takes a Camera and a sink closure, runs the frame loop on its own thread, and returns a Pump handle with three operations:
pump::set_active(&pump, bool): pause or resume streaming without closing the camera (no per-frame work while paused).pump::capture_frame(&pump) -> Option<Frame>: fetch a single fresh frame on demand, works whether the pump is active or paused.pump::stop_and_join(pump): deterministic teardown.
use pump;
Pause eliminates Rust-side per-frame work. The OS camera pipeline keeps running. See the pump module docs for the full trade-off.
Dioxus integration
If you are building a Dioxus app, see the companion crate dioxus-cameras, which provides:
use_camera_streamhook withactive+capture_frameon the returned handle.use_devicesanduse_streamshooks for camera enumeration and multi-stream id management.- A loopback HTTP preview server plus a WebGL2 canvas renderer (
StreamPreview+PreviewScript).
Testing RTSP Locally
The demo/ app can view RTSP streams on macOS and Windows. To exercise the full path without a real IP camera, serve a local MP4 as an RTSP stream using mediamtx and ffmpeg (both on PATH):
# terminal 1: start mediamtx with the repo's mediamtx.yml
# terminal 2: publish an MP4 file as an RTSP stream on rtsp://127.0.0.1:8554/live
# terminal 3: launch the demo app
In the demo window, switch the source toggle to RTSP, paste rtsp://127.0.0.1:8554/live into the URL field, and press Connect. On macOS and Windows, H.264/H.265 streams are hardware-decoded (VideoToolbox / Media Foundation); MJPEG streams are delivered verbatim and decoded via zune-jpeg on demand.
Examples
Runnable integration templates for using cameras outside Dioxus (CLI, egui / iced, Tauri, daemons, anything). See the examples directory.
| Example | What it shows |
|---|---|
snapshot |
Open, grab one frame, save as PNG. to_rgba8 + file I/O. |
pump |
pump::spawn with a closure sink, set_active pause/resume, capture_frame while paused. The template for plugging cameras into your own runtime. |
monitor |
Camera hotplug event loop with monitor + next_event. |
Publishing
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.