forked from nashaofu/xcap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwindow_record.rs
70 lines (58 loc) · 1.69 KB
/
window_record.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use fs_extra::dir;
use std::{
thread,
time::{Duration, Instant},
};
use xcap::Window;
fn main() {
let windows = Window::all().unwrap();
dir::create_all("target/windows", true).unwrap();
let mut i = 0;
for window in &windows {
// 最小化的窗口不能截屏
if window.is_minimized() {
continue;
}
if window.title().contains("Chrome") {
break;
}
println!(
"Window: {:?} {:?} {:?}",
window.title(),
(window.x(), window.y(), window.width(), window.height()),
(window.is_minimized(), window.is_maximized())
);
i += 1;
}
let mut win = windows.get(i).unwrap().clone();
println!("{:?}", win);
let mut i = 0;
let frame = 20;
let start = Instant::now();
let fps = 1000 / frame;
loop {
i += 1;
let time = Instant::now();
win.refresh().unwrap();
let image = win.capture_image().unwrap();
image
.save(format!("target/windows/window-{}.png", i,))
.unwrap();
let sleep_time = fps * i - start.elapsed().as_millis() as i128;
println!(
"sleep_time: {:?} current_step_time: {:?}",
sleep_time,
time.elapsed()
);
if sleep_time > 0 {
thread::sleep(Duration::from_millis(sleep_time as u64));
}
if i >= 900 {
break;
}
}
println!("time {:?}", start.elapsed());
let actual_fps = 900 / start.elapsed().as_secs();
println!("actual fps: {}", actual_fps);
// ffmpeg -framerate {actual_fps} -i window-%d.png -c:v libx264 -pix_fmt yuv420p output.mp4
}