ffmpeg_light/
filter.rs

1//! Helper types for common FFmpeg video filters.
2
3use std::fmt;
4
5use crate::types::Time;
6
7/// Filters supported by the high-level API.
8#[derive(Clone, Debug, PartialEq)]
9pub enum VideoFilter {
10    /// Scale video to the provided width/height.
11    Scale {
12        /// Target width in pixels.
13        width: u32,
14        /// Target height in pixels.
15        height: u32,
16    },
17    /// Trim video between `start` and optional `end` timestamps.
18    Trim {
19        /// Starting timestamp for the trim window.
20        start: Time,
21        /// Optional end timestamp; `None` trims until the end of the input.
22        end: Option<Time>,
23    },
24    /// Custom filter string for advanced use-cases.
25    Custom(String),
26}
27
28impl VideoFilter {
29    /// Serialize into an FFmpeg `-vf` snippet.
30    pub fn to_filter_string(&self) -> String {
31        match self {
32            VideoFilter::Scale { width, height } => format!("scale={width}:{height}"),
33            VideoFilter::Trim { start, end } => match end {
34                Some(end) => format!("trim=start={start}:end={end}"),
35                None => format!("trim=start={start}"),
36            },
37            VideoFilter::Custom(raw) => raw.clone(),
38        }
39    }
40}
41
42impl fmt::Display for VideoFilter {
43    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44        write!(f, "{}", self.to_filter_string())
45    }
46}