Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
louis030195 opened this issue Aug 24, 2024 · 1 comment

Comments

@louis030195
Copy link

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
Copy link

n1ght-hunter commented Oct 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants