ccap provides first-class Rust bindings via the ccap-rs crate.
- Crate: ccap-rs on crates.io
- API docs: docs.rs/ccap-rs
- Source in this repo:
bindings/rust/
Note: The published crate name is
ccap-rs, but the library name isccapso you can writeuse ccap::Provider;.
cargo add ccap-rsIf you prefer using ccap as the crate name in code (recommended):
[dependencies]
ccap = { package = "ccap-rs", version = "<latest>" }use ccap::{Provider, Result};
fn main() -> Result<()> {
let mut provider = Provider::new()?;
let devices = provider.find_device_names()?;
if let Some(device) = devices.first() {
provider.open_device(Some(device), true)?;
if let Some(frame) = provider.grab_frame(3000)? {
let info = frame.info()?;
println!("{}x{} {:?}", info.width, info.height, info.pixel_format);
}
}
Ok(())
}build-source(default): build the underlying C/C++ sources as part ofcargo build.- Best for crates.io users.
static-link: link against a pre-built static library from a CameraCapture checkout.- Best for development when you are working on both C/C++ and Rust.
- If the build script cannot find the repo root automatically, set
CCAP_SOURCE_DIR.
This is the recommended mode for typical users.
- Requirements: Rust 1.65+, CMake 3.14+.
- The crate builds the C/C++ sources during compilation.
This mode expects a pre-built ccap static library under a CameraCapture checkout:
- Build the C/C++ project first (Debug or Release).
- Then build your Rust project with the
static-linkfeature.
If needed, set:
CCAP_SOURCE_DIR=/path/to/CameraCapture
Camera capture backends:
- Windows: dual backends, with DirectShow by default and Media Foundation fully supported
- macOS/iOS: AVFoundation
- Linux: V4L2
On Windows, camera capture defaults to DirectShow because virtual cameras such as OBS Virtual Camera are exposed there more reliably. Media Foundation is also a first-class supported backend. You can select auto, msmf, or dshow via CCAP_WINDOWS_BACKEND, or pass the same values into the Rust APIs Provider::with_device_name_and_extra_info, Provider::with_device_and_extra_info, Provider::open_device_with_extra_info, and Provider::open_with_index_and_extra_info.
Video file playback support depends on the underlying C/C++ backend (currently Windows/macOS only).
- Main ccap Documentation (English) / 主文档 (中文)
- C Interface Documentation (English) / C 接口文档 (中文)
- CLI Tool Guide (English) / CLI 工具指南 (中文)