-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdrain-stream.rs
More file actions
61 lines (48 loc) · 1.44 KB
/
drain-stream.rs
File metadata and controls
61 lines (48 loc) · 1.44 KB
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
//! Captures video and ignores the video data (printing a `.` to the screen for every frame
//! received).
//!
//! Uses the [`linuxvideo::stream::ReadStream`] returned by [`linuxvideo::VideoCaptureDevice::into_stream`]
//! to read image data.
use std::{
env,
io::Write,
path::Path,
time::{Duration, Instant},
};
use linuxvideo::{
format::{PixFormat, Pixelformat},
Device,
};
fn main() -> linuxvideo::Result<()> {
env_logger::init();
let mut args = env::args_os().skip(1);
let path = match args.next() {
Some(path) => path,
None => {
println!("usage: drain-stream <device>");
std::process::exit(1);
}
};
let device = Device::open(Path::new(&path))?;
println!(
"capabilities: {:?}",
device.capabilities()?.device_capabilities()
);
let capture = device.video_capture(PixFormat::new(u32::MAX, u32::MAX, Pixelformat::YUYV))?;
println!("negotiated format: {:?}", capture.format());
let mut stream = capture.into_stream(2)?;
println!("stream started, waiting for data");
let mut frames = 0;
let mut time = Instant::now();
loop {
stream.dequeue(|_buf| Ok(()))?;
frames += 1;
print!(".");
std::io::stdout().flush().ok();
if time.elapsed() >= Duration::from_secs(1) {
println!(" {} FPS", frames);
time = Instant::now();
frames = 0;
}
}
}