-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ci: add cargo check without default features on mac m1 * refactor: prevent unused imports on all feature combinations * refactor: organize imports so cargo test passes without default features * docs: include and annotate optional features in cargo doc output * refactor: clean up scripts * docs: add missing rustdoc to most modules and structs * docs: simplify hello world * feat: re-export anyhow::Result
- Loading branch information
1 parent
31f93bd
commit ba61aca
Showing
24 changed files
with
206 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,23 @@ | ||
use ffmpeg_sidecar::{command::FfmpegCommand, event::FfmpegEvent}; | ||
use ffmpeg_sidecar::command::FfmpegCommand; | ||
|
||
/// 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 | ||
// Run an FFmpeg command that generates a test video | ||
let iter = 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 | ||
} | ||
FfmpegEvent::ParsedInputStream(stream) => { | ||
if let Some(video_data) = stream.video_data() { | ||
println!( | ||
"Found video stream with index {} in input {} that has fps {}, width {}px, height {}px.", | ||
stream.stream_index, | ||
stream.parent_index, | ||
video_data.fps, | ||
video_data.width, | ||
video_data.height | ||
); | ||
} | ||
} | ||
_ => {} | ||
} | ||
}); | ||
.spawn()? // <- Ordinary `std::process::Child` | ||
.iter()?; // <- Blocking iterator over logs and output | ||
|
||
// Use a regular "for" loop to read decoded video data | ||
for frame in iter.filter_frames() { | ||
println!("frame: {}x{}", frame.width, frame.height); | ||
let _pixels: Vec<u8> = frame.data; // <- raw RGB pixels! 🎨 | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
# Source: <https://users.rust-lang.org/t/how-to-document-optional-features-in-api-docs/64577> | ||
|
||
# First, install nightly toolchain if needed: | ||
# rustup install nightly | ||
|
||
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --open |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/bin/bash | ||
|
||
# Backtrace is on by default, and does not respect Cargo.toml | ||
# [env] section, even with force = true. | ||
export RUST_BACKTRACE=0 | ||
cargo test | ||
RUST_BACKTRACE=0 cargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
exit 1 # snippets only, not meant to be run together | ||
#!/bin/bash | ||
|
||
# testsrc | ||
ffmpeg \ | ||
-v level+info \ | ||
-f lavfi \ | ||
-i testsrc \ | ||
-y output/test.mp4 | ||
# Each function body is intended to be copy-pasted directly into a terminal. | ||
|
||
testsrc() { | ||
ffmpeg \ | ||
-v level+info \ | ||
-f lavfi \ | ||
-i testsrc \ | ||
-y output/test.mp4 | ||
} | ||
|
||
toDevNull() { | ||
ffmpeg \ | ||
-v level+info \ | ||
-f lavfi \ | ||
-i testsrc \ | ||
-f rawvideo \ | ||
-pix_fmt rgb24 \ | ||
pipe > /dev/null | ||
} | ||
|
||
# to /dev/null | ||
ffmpeg \ | ||
-v level+info \ | ||
-f lavfi \ | ||
-i testsrc \ | ||
-f rawvideo \ | ||
-pix_fmt rgb24 \ | ||
pipe > /dev/null | ||
# to stdout: 'pipe', 'pipe:', 'pipe:1', '-' | ||
# to stderr: 'pipe:2' | ||
|
||
# pix_fmts | ||
ffmpeg -hide_banner -pix_fmts | ||
pix_fmts() { | ||
ffmpeg -hide_banner -pix_fmts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.