CapSoftware / scap

High-performance, cross-platform screen capture library in Rust.
https://crates.io/crates/scap
Other
229 stars 44 forks source link

window specific target does not work "Failed due to an invalid parameter" #116

Open louis030195 opened 3 months ago

louis030195 commented 3 months ago

mac book bro m3 14.5

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

"Failed due to an invalid parameter"

here

#[cfg(target_os = "macos")]
{
    // self.mac.add_output(Capturer::new(tx));
    self.mac.start_capture().expect("Failed to start capture");
}
n1ght-hunter commented 1 month ago

i also have this issue was it ever figured out the cause? it somthing to do with the target being a window i think