Skip to content

monitor_record example runs too slow. #230

@qzd1989

Description

@qzd1989

I printed the elapsed time and I found it runs too slow on my macbook pro.

use std::{
    thread,
    time::{Duration, Instant},
};
use xcap::Monitor;
fn main() {
    let monitors = Monitor::all().unwrap();
    let monitor = monitors.first().unwrap();
    let (video_recorder, sx) = monitor.video_recorder().unwrap();
    let now = Instant::now();
    thread::spawn(move || loop {
        match sx.recv() {
            Ok(frame) => {
                println!(" time elasped: {:?}", now.elapsed());
            }
            _ => continue,
        }
    });

    println!("start");
    video_recorder.start().unwrap();
    thread::sleep(Duration::from_secs(5000));
    println!("stop");
    video_recorder.stop().unwrap();
}

output

 time elasped: 557.709916ms
 time elasped: 835.701208ms
 time elasped: 1.112399291s
 time elasped: 1.389329208s
 time elasped: 1.666982041s
 time elasped: 1.9431185s
 time elasped: 2.216904708s
 time elasped: 2.49546275s
 time elasped: 2.770125125s
 time elasped: 3.044409083s
 time elasped: 3.32939825s
 time elasped: 3.614606041s
 time elasped: 3.897295541s
 time elasped: 4.175439541s
 time elasped: 4.450887833s
 time elasped: 4.724580208s
 time elasped: 4.998677458s

my counputer:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions