-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
main.rs
123 lines (113 loc) · 3.61 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// This program is just a testing application
// Refer to `lib.rs` for the library source code
use scap::{
capturer::{Area, Capturer, Options, Point, Size},
frame::Frame
,
};
use std::process;
fn main() {
// Check if the platform is supported
if !scap::is_supported() {
println!("❌ Platform not supported");
return;
}
// Check if we have permission to capture screen
// If we don't, request it.
if !scap::has_permission() {
println!("❌ Permission not granted. Requesting permission...");
if !scap::request_permission() {
println!("❌ Permission denied");
return;
}
}
// // Get recording targets
// let targets = scap::get_all_targets();
// Create Options
let options = Options {
fps: 60,
show_cursor: true,
show_highlight: true,
excluded_targets: None,
output_type: scap::frame::FrameType::BGRAFrame,
output_resolution: scap::capturer::Resolution::_720p,
crop_area: Some(Area {
origin: Point { x: 0.0, y: 0.0 },
size: Size {
width: 500.0,
height: 500.0,
},
}),
..Default::default()
};
// Create Recorder with options
let mut recorder = Capturer::build(options).unwrap_or_else(|err| {
println!("Problem with building Capturer: {err}");
process::exit(1);
});
// Start Capture
recorder.start_capture();
// Capture 100 frames
let mut start_time: u64 = 0;
for i in 0..100 {
let frame = recorder.get_next_frame().expect("Error");
match frame {
Frame::YUVFrame(frame) => {
println!(
"Recieved YUV frame {} of width {} and height {} and pts {}",
i, frame.width, frame.height, frame.display_time
);
}
Frame::BGR0(frame) => {
println!(
"Received BGR0 frame of width {} and height {}",
frame.width, frame.height
);
}
Frame::RGB(frame) => {
if start_time == 0 {
start_time = frame.display_time;
}
println!(
"Recieved RGB frame {} of width {} and height {} and time {}",
i,
frame.width,
frame.height,
frame.display_time - start_time
);
}
Frame::RGBx(frame) => {
println!(
"Recieved RGBx frame of width {} and height {}",
frame.width, frame.height
);
}
Frame::XBGR(frame) => {
println!(
"Recieved xRGB frame of width {} and height {}",
frame.width, frame.height
);
}
Frame::BGRx(frame) => {
println!(
"Recieved BGRx frame of width {} and height {}",
frame.width, frame.height
);
}
Frame::BGRA(frame) => {
if start_time == 0 {
start_time = frame.display_time;
}
println!(
"Recieved BGRA frame {} of width {} and height {} and time {}",
i,
frame.width,
frame.height,
frame.display_time - start_time
);
}
}
}
// Stop Capture
recorder.stop_capture();
}