scap icon indicating copy to clipboard operation
scap copied to clipboard

Giving OutputType isn't Working Properly

Open Tahinli opened this issue 10 months ago • 1 comments

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

Tahinli avatar Mar 08 '25 17:03 Tahinli

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.

MAlba124 avatar Mar 10 '25 17:03 MAlba124