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

Does not work on linux #132

Open
MyrikLD opened this issue Nov 12, 2024 · 2 comments
Open

Does not work on linux #132

MyrikLD opened this issue Nov 12, 2024 · 2 comments

Comments

@MyrikLD
Copy link

MyrikLD commented Nov 12, 2024

I keep getting the first image, the picture doesn't change.
Wayland, Hyprland, Pipewire

use anyhow::Result;
use image::{DynamicImage, RgbImage};
use scap::capturer::{Capturer, Options};
use scap::frame::{convert_bgra_to_rgb, BGRxFrame, Frame};

fn get_image(_f: &BGRxFrame) -> Result<DynamicImage> {
    println!("get_image: {}", _f.display_time);

    let Some(rgb) = RgbImage::from_vec(
        _f.width as u32,
        _f.height as u32,
        convert_bgra_to_rgb(_f.data.to_vec()),
    ) else { panic!("Invalid frame") };

    let img = DynamicImage::ImageRgb8(rgb);

    Ok(img)
}

fn main() -> Result<()> {
    // Create Options
    let options = Options {
        fps: 1,
        target: None, // None captures the primary display
        show_cursor: false,
        crop_area: None,
        show_highlight: true,
        excluded_targets: None,
        output_type: scap::frame::FrameType::BGR0,
        output_resolution: scap::capturer::Resolution::_480p,
    };

    // Create Capturer
    let mut capturer = Capturer::build(options)?;

    capturer.start_capture();

    loop {
        let f = match capturer.get_next_frame()? {
            Frame::BGRx(f1) => f1,
            _ => panic!("Unsupported frame type"),
        };

        let img = get_image(&f)?;

        img.save(format!("{}.png", f.display_time))?;
    }

    // Stop Capture
    capturer.stop_capture();
}
@MyrikLD MyrikLD changed the title Does not working on linux Does not work on linux Nov 12, 2024
@MAlba124
Copy link
Contributor

I'm able to reproduce. The reason for this is because the wayland implementation ignores the fps option and just forwards all the frames it receives to scap consumer, in this case, the frame conversion and image saving is too slow to keep up with the backlog of new frames. I would write a fix for this, but seeing my trivial fixes don't get merged gives me the impression that the maintainers don't care.

@Brendonovich
Copy link
Member

We'll get those PRs merged once we have linux environments to test on, if you do write a fix for this we'll definitely get it merged.

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

3 participants