use sc_cap::{
capturer::{Area, Capturer, Options, Point, Size},
frame::{Frame, VideoFrame},
};
use std::process;
fn main() {
if !sc_cap::is_supported() {
println!("❌ Platform not supported");
return;
}
if !sc_cap::has_permission() {
println!("❌ Permission not granted. Requesting permission...");
if !sc_cap::request_permission() {
println!("❌ Permission denied");
return;
}
}
let options = Options {
fps: 60,
show_cursor: true,
show_highlight: false,
excluded_targets: None,
output_type: sc_cap::frame::FrameType::BGRAFrame,
output_resolution: sc_cap::capturer::Resolution::_720p,
crop_area: Some(Area {
origin: Point { x: 0.0, y: 0.0 },
size: Size {
width: 500.0,
height: 500.0,
},
}),
captures_audio: true,
..Default::default()
};
let mut recorder = Capturer::build(options).unwrap_or_else(|err| {
println!("Problem with building Capturer: {err}");
process::exit(1);
});
recorder.start_capture();
for i in 0..100 {
let frame = loop {
match recorder.get_next_frame().expect("Error") {
Frame::Video(frame) => {
break frame;
}
Frame::Audio(_) => {
continue;
}
}
};
match frame {
VideoFrame::YUVFrame(frame) => {
println!(
"Recieved YUV frame {} of width {} and height {} and pts {:?}",
i, frame.width, frame.height, frame.display_time
);
}
VideoFrame::BGR0(frame) => {
println!(
"Received BGR0 frame of width {} and height {}",
frame.width, frame.height
);
}
VideoFrame::RGB(frame) => {
println!(
"Recieved RGB frame {} of width {} and height {} and time {:?}",
i, frame.width, frame.height, frame.display_time
);
}
VideoFrame::RGBx(frame) => {
println!(
"Recieved RGBx frame of width {} and height {}",
frame.width, frame.height
);
}
VideoFrame::XBGR(frame) => {
println!(
"Recieved xRGB frame of width {} and height {}",
frame.width, frame.height
);
}
VideoFrame::BGRx(frame) => {
println!(
"Recieved BGRx frame of width {} and height {}",
frame.width, frame.height
);
}
VideoFrame::BGRA(frame) => {
println!(
"Recieved BGRA frame {} of width {} and height {} and time {:?}",
i, frame.width, frame.height, frame.display_time
);
}
}
}
recorder.stop_capture();
}