Skip to content

Latest commit

 

History

History
91 lines (60 loc) · 2.92 KB

File metadata and controls

91 lines (60 loc) · 2.92 KB

Rust Bindings

ccap provides first-class Rust bindings via the ccap-rs crate.

Note: The published crate name is ccap-rs, but the library name is ccap so you can write use ccap::Provider;.

Quick Start

Add dependency

cargo add ccap-rs

If you prefer using ccap as the crate name in code (recommended):

[dependencies]
ccap = { package = "ccap-rs", version = "<latest>" }

Minimal example

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(())
}

Feature flags

  • build-source (default): build the underlying C/C++ sources as part of cargo 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.

Build notes

Using build-source (default)

This is the recommended mode for typical users.

  • Requirements: Rust 1.65+, CMake 3.14+.
  • The crate builds the C/C++ sources during compilation.

Using static-link

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-link feature.

If needed, set:

  • CCAP_SOURCE_DIR=/path/to/CameraCapture

Platform support

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).

See also