easy_ffprobe/
config.rs

1use crate::{error::FfProbeError, ffprobe::FfProbe, ffprobe_config};
2
3/// ffprobe configuration.
4///
5/// Use [`Config::new`] for constructing a new config.
6#[derive(Clone, Debug)]
7pub struct Config {
8    pub(crate) count_frames: bool,
9    pub(crate) ffprobe_bin: std::path::PathBuf,
10}
11
12impl Config {
13    /// Construct a new Config.
14    pub fn new() -> Config {
15        Config {
16            count_frames: false,
17            ffprobe_bin: "ffprobe".into(),
18        }
19    }
20
21    /// Enable the -count_frames setting.
22    /// Will fully decode the file and count the frames.
23    /// Frame count will be available in [`Stream::nb_read_frames`].
24    pub fn count_frames(mut self, count_frames: bool) -> Self {
25        self.count_frames = count_frames;
26        self
27    }
28
29    /// Specify which binary name (e.g. `"ffprobe-6"`) or path (e.g. `"/opt/bin/ffprobe"`) to use
30    /// for executing `ffprobe`.
31    pub fn ffprobe_bin(mut self, ffprobe_bin: impl AsRef<std::path::Path>) -> Self {
32        self.ffprobe_bin = ffprobe_bin.as_ref().to_path_buf();
33        self
34    }
35
36    /// Run ffprobe with the config produced by this builder.
37    pub fn run(self, path: impl AsRef<std::path::Path>) -> Result<FfProbe, FfProbeError> {
38        ffprobe_config(self, path)
39    }
40}
41
42impl Default for Config {
43    fn default() -> Self {
44        Self::new()
45    }
46}