forked from nathanbabcock/ffmpeg-sidecar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_world.rs
30 lines (29 loc) · 1.05 KB
/
hello_world.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
use ffmpeg_sidecar::{command::FfmpegCommand, event::FfmpegEvent};
/// Iterates over the frames of a `testsrc`.
///
/// ```console
/// cargo run --example hello_world
/// ```
fn main() -> anyhow::Result<()> {
FfmpegCommand::new() // <- Builder API like `std::process::Command`
.testsrc() // <- Discoverable aliases for FFmpeg args
.rawvideo() // <- Convenient argument presets
.spawn()? // <- Uses an ordinary `std::process::Child`
.iter()? // <- Iterator over all log messages and video output
.for_each(|event: FfmpegEvent| {
match event {
FfmpegEvent::OutputFrame(frame) => {
println!("frame: {}x{}", frame.width, frame.height);
let _pixels: Vec<u8> = frame.data; // <- raw RGB pixels! 🎨
}
FfmpegEvent::Progress(progress) => {
eprintln!("Current speed: {}x", progress.speed); // <- parsed progress updates
}
FfmpegEvent::Log(_level, msg) => {
eprintln!("[ffmpeg] {}", msg); // <- granular log message from stderr
}
_ => {}
}
});
Ok(())
}