Crates.io | crabgrab |
lib.rs | crabgrab |
version | 0.4.0 |
source | src |
created_at | 2024-04-19 21:57:32.000503 |
updated_at | 2024-06-14 21:48:44.038723 |
description | A cross-platform screen/window capture crate |
homepage | https://github.com/AugmendTech/CrabGrab |
repository | https://github.com/AugmendTech/CrabGrab |
max_upload_size | |
id | 1214127 |
size | 420,362 |
A cross-platform screen-capturing crate for rust
Capturing video from screens and applications can be very hard, and it's even worse when you want to do it in a cross-platform application. CrabGrab makes it easy to do continuous frame capture that can be used for individual screenshots or for capturing video. It also includes common functionality needed for enumerating screens and applications. You can get from a window to a pixel buffer in just a few lines of code that will work on both Windows and MacOS.
#[tokio::main]
async fn main() {
let token = match CaptureStream::test_access(false) {
Some(token) => token,
None => CaptureStream::request_access(false).await.expect("Expected capture access")
};
let filter = CapturableContentFilter::NORMAL_WINDOWS;
let content = CapturableContent::new(filter).await.unwrap();
let config = CaptureConfig::with_display(content.displays().next().unwrap(), CapturePixelFormat::Bgra8888);
let mut stream = CaptureStream::new(token, config, |stream_event| {
// The stream_event here could be a video frame or audio frame
println!("result: {:?}", stream_event);
}).unwrap();
std::thread::sleep(Duration::from_millis(2000));
stream.stop().unwrap();
}
With CrabGrab, you can build things like:
For a full application example, check out Snippy, an AI assistant built on top of CrabGrab.
Small examples showing how to use the CrabGrab crate can be found at crabgrab/examples. You can run the examples from the repository:
cargo run --example <example_name>
Note that feature examples will require that feature:
cargo run --example <example name> --feature <feature name>
Unfortunately due to our dependence on metal-rs, building docs for macos doesn't work on docs.rs, since they use linux containers. As a workaround, we host macos documentation in this repository - link above.
All contributions are welcome! We are actively working on this project and are looking to expand the capabilities including sound capture, Linux support, and performance improvements.