Skip to main content

aether_renderer_core/ffmpeg/
mod.rs

1pub mod gif;
2/// FFmpeg rendering helpers for different output formats
3pub mod video;
4
5use std::io::Read;
6
7/// Where ffmpeg reads the frames from.
8pub(crate) enum FfmpegInput<'a> {
9    /// An image input such as `frames/%06d.png` (or a glob, for callers that pass one).
10    Sequence(&'a str),
11    /// Concatenated PNG files on ffmpeg's stdin, fed from this reader.
12    PngStream(Box<dyn Read + Send>),
13}
14
15impl FfmpegInput<'_> {
16    /// The ffmpeg input arguments, and the reader to feed to its stdin, if any.
17    pub(crate) fn into_args(self, fps: u32) -> (Vec<String>, Option<Box<dyn Read + Send>>) {
18        let fps = fps.to_string();
19        match self {
20            Self::Sequence(pattern) => {
21                let mut args = vec!["-framerate".into(), fps];
22                if pattern.contains('*') {
23                    args.extend(["-pattern_type".into(), "glob".into()]);
24                }
25                args.extend(["-i".into(), pattern.to_string()]);
26                (args, None)
27            }
28            Self::PngStream(reader) => (
29                vec![
30                    "-f".into(),
31                    "image2pipe".into(),
32                    "-framerate".into(),
33                    fps,
34                    "-c:v".into(),
35                    "png".into(),
36                    "-i".into(),
37                    "pipe:0".into(),
38                ],
39                Some(reader),
40            ),
41        }
42    }
43}