use std::fs;
use std::io;
use std::io::Write;
use vidi;
use vidi::{Config, CaptureStream, FourCC};
fn main() -> io::Result<()> {
let cameras_list = vidi::actors::camera_list::spawn()?;
let cameras = cameras_list.cameras();
let camera = cameras_list.create(&cameras[0].info.id)
.expect("No such camera")
.expect("Failed to get camera");
dbg!(camera.get_id());
{
let mut camera = camera.acquire();
if let Ok(ref mut camera) = camera {
let mut stream = camera.start(
Config{fourcc: FourCC::new(b"YUYV"), width: 640, height: 480},
4
).unwrap();
let (buf, meta, _next) = stream.next().unwrap();
let mmap = buf.memory_map_ro().unwrap();
let data = mmap.as_slice();
println!(
"Buffer size: {}, seq: {}, timestamp: {}",
data.len(),
meta.sequence,
meta.timestamp
);
fs::File::create("frame.yuyv").unwrap().write_all(&data).unwrap();
}
}
Ok(())
}