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

Giving OutputType isn't Working Properly #151

Open
Tahinli opened this issue Mar 8, 2025 · 1 comment
Open

Giving OutputType isn't Working Properly #151

Tahinli opened this issue Mar 8, 2025 · 1 comment

Comments

@Tahinli
Copy link

Tahinli commented Mar 8, 2025

Hi,

use image::ColorType;
use scap::{
    capturer::{self, Capturer},
    frame::convert_bgra_to_rgb,
};
use tokio::time::Instant;

#[tokio::main]
async fn main() {
    println!("Hello, world!");

    assert!(scap::is_supported());
    assert!(scap::request_permission());
    assert!(scap::has_permission());

    let capturer_options = capturer::Options {
        output_type: scap::frame::FrameType::RGB,
        ..Default::default()
    };
    let mut recorder = Capturer::build(capturer_options).unwrap();
    recorder.start_capture();
    let time = Instant::now();
    std::io::stdin().read_line(&mut String::default()).unwrap();
    recorder.stop_capture();
    let record_time = time.elapsed();
    println!("{:#?}", record_time);
    let mut buf = vec![];
    let mut width = 0;
    let mut height = 0;
    while let Ok(frame) = recorder.get_next_frame() {
        match frame {
            scap::frame::Frame::BGRx(bgrx_frame) => {
                buf.push(convert_bgra_to_rgb(bgrx_frame.data));
                width = bgrx_frame.width as u32;
                height = bgrx_frame.height as u32;
            }

            _ => unreachable!("Where is my BGR"),
        }
    }
    println!("Total Frame = {}", buf.len());
    println!("FPS = {}", buf.len() as u64 / record_time.as_secs());
    for (i, frame) in buf.iter().enumerate() {
        let location = format!("frames/{}.png", i);
        image::save_buffer(location, frame, width, height, ColorType::Rgb8).unwrap();
    }
}

Even if I gave RGB output is always BGRx for me.

I'm using Hyprland

@MAlba124
Copy link
Contributor

The wayland backend ignores the pixel format as it cannot force it, and no conversion is done either because it can be very expensive. This should be documented.

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