use scap::{
capturer::{Capturer, Options},
frame::Frame,
Target,
};
fn main() {
if !scap::is_supported() {
println!("❌ Platform not supported");
return;
}
if !scap::has_permission() {
println!("❌ Permission not granted. Requesting permission...");
if !scap::request_permission() {
println!("❌ Permission denied");
return;
}
}
// Get all available targets (windows)
let targets = scap::get_all_targets();
// filter only to be Target::Window
let targets: Vec<Target> = targets
.into_iter()
.filter(|target| matches!(target, Target::Window(_)))
.collect();
for target in targets {
let options = Options {
fps: 60,
show_cursor: true,
show_highlight: true,
excluded_targets: None,
output_type: scap::frame::FrameType::BGRAFrame,
output_resolution: scap::capturer::Resolution::_720p,
target: Some(target.clone()),
..Default::default()
};
let mut recorder = Capturer::new(options);
recorder.start_capture();
// Capture 10 frames from each window
for i in 0..10 {
if let Ok(frame) = recorder.get_next_frame() {
match frame {
Frame::BGRA(frame) => {
println!(
"Received BGRA frame {} of width {} and height {} at time {}",
i, frame.width, frame.height, frame.display_time
);
}
// Handle other frame types if needed
_ => println!("Received non-BGRA frame"),
}
} else {
println!("Error capturing frame");
}
}
recorder.stop_capture();
}
}
mac book bro m3 14.5
here