Skip to content

Commit

Permalink
refactor: filter frames vs chunks separately
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanbabcock committed Feb 21, 2023
1 parent 2423948 commit 2f6d62d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/h265_transcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {

// Frames can be transformed by Iterator `.map()`.
// This example is a no-op, with frames passed through unaltered.
let transformed_frames = input.iter().unwrap().filter_output().map(|f| f);
let transformed_frames = input.iter().unwrap().filter_frames().map(|f| f);

// You could easily add some "middleware" processing here:
// - overlay or composite another RGB image (or even another Ffmpeg Iterator)
Expand Down
11 changes: 11 additions & 0 deletions examples/tee.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use ffmpeg_sidecar::{command::FfmpegCommand, error::Error};

fn main() -> Result<(), Error> {
let _cmd = FfmpegCommand::new()
.testsrc()
.output("pipe")
.spawn()?
.iter()?;

Ok(())
}
10 changes: 9 additions & 1 deletion src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,21 @@ impl FfmpegIterator {
}

/// Filter out all events except for output frames (`FfmpegEvent::OutputFrame`).
pub fn filter_output(self) -> impl Iterator<Item = OutputVideoFrame> {
pub fn filter_frames(self) -> impl Iterator<Item = OutputVideoFrame> {
self.filter_map(|event| match event {
FfmpegEvent::OutputFrame(o) => Some(o),
_ => None,
})
}

/// Filter out all events except for output chunks (`FfmpegEvent::OutputChunk`).
pub fn filter_chunks(self) -> impl Iterator<Item = Vec<u8>> {
self.filter_map(|event| match event {
FfmpegEvent::OutputChunk(vec) => Some(vec),
_ => None,
})
}

/// Iterator over every message from ffmpeg's stderr as a raw string.
/// Conceptually equivalent to `BufReader::new(ffmpeg_stderr).lines()`.
pub fn into_ffmpeg_stderr(self) -> impl Iterator<Item = String> {
Expand Down

0 comments on commit 2f6d62d

Please sign in to comment.