l1npengtul / nokhwa

Cross Platform Rust Library for Powerful Webcam/Camera Capture
Apache License 2.0
482 stars 111 forks source link
avfoundation camera camera-api cross-platform linux macos mediafoundation rust v4l2 webcam webcam-capture windows

cargo version docs.rs version

nokhwa

Nokhwa(녹화): Korean word meaning "to record".

A Simple-to-use, cross-platform Rust Webcam Capture Library

Using nokhwa

Nokhwa can be added to your crate by adding it to your Cargo.toml:

[dependencies.nokhwa]
version = "0.10.0"
# Use the native input backends, enable WGPU integration
features = ["input-native", "output-wgpu"]

Most likely, you will only use functionality provided by the Camera struct. If you need lower-level access, you may instead opt to use the raw capture backends found at nokhwa::backends::capture::*.

Example

// first camera in system
let index = CameraIndex::Index(0); 
// request the absolute highest resolution CameraFormat that can be decoded to RGB.
let requested = RequestedFormat::new::<RgbFormat>(RequestedFormatType::AbsoluteHighestFrameRate);
// make the camera
let mut camera = Camera::new(index, requested).unwrap();

// get a frame
let frame = camera.frame().unwrap();
println!("Captured Single Frame of {}", frame.buffer().len());
// decode into an ImageBuffer
let decoded = frame.decode_image::<RgbFormat>().unwrap();
println!("Decoded Frame of {}", decoded.len());

A command line app made with nokhwa can be found in the examples folder.

API Support

The table below lists current Nokhwa API support.

Feature

The default feature includes nothing. Anything starting with input-* is a feature that enables the specific backend.

input-* features:

Conversely, anything that starts with output-* controls a feature that controls the output of something (usually a frame from the camera)

output-* features:

Other features:

You many want to pick and choose to reduce bloat.

Issues

If you are making an issue, please make sure that

Contributing

Contributions are welcome!

Minimum Service Rust Version

nokhwa may build on older versions of rustc, but there is no guarantee except for the latest stable rust.

Sponsors

Please consider donating! It helps me not look like a failure to my parents!