MCPcopy Create free account
hub / github.com/Recordscript/recordscript / main

Function main

libs/scrap/examples/ffplay.rs:7–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5extern crate scrap;
6
7fn main() {
8 use scrap::{Capturer, Display, TraitCapturer};
9 use std::io::ErrorKind::WouldBlock;
10 use std::io::Write;
11 use std::process::{Command, Stdio};
12
13 let d = Display::primary().unwrap();
14 let (w, h) = (d.width(), d.height());
15
16 let child = Command::new("ffplay")
17 .args(&[
18 "-f",
19 "rawvideo",
20 "-pixel_format",
21 "bgr0",
22 "-video_size",
23 &format!("{}x{}", w, h),
24 "-framerate",
25 "60",
26 "-",
27 ])
28 .stdin(Stdio::piped())
29 .spawn()
30 .expect("This example requires ffplay.");
31
32 let mut capturer = Capturer::new(d).unwrap();
33 let mut out = child.stdin.unwrap();
34
35 loop {
36 match capturer.frame(Duration::from_millis(0)) {
37 Ok(frame) => {
38 // Write the frame, removing end-of-row padding.
39 let Frame::PixelBuffer(frame) = frame else {
40 return;
41 };
42 let stride = frame.stride()[0];
43 let rowlen = 4 * w;
44 for row in frame.data().chunks(stride) {
45 let row = &row[..rowlen];
46 out.write_all(row).unwrap();
47 }
48 }
49 Err(ref e) if e.kind() == WouldBlock => {
50 // Wait for the frame.
51 }
52 Err(_) => {
53 // We're done here.
54 break;
55 }
56 }
57 }
58}

Callers

nothing calls this directly

Calls 5

widthMethod · 0.45
heightMethod · 0.45
frameMethod · 0.45
strideMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected