1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::str::FromStr;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum FFmpegError {
    #[error("Unknown preset: {name}")]
    PresetUnknown { name: String },
}

#[derive(Clone, PartialEq, PartialOrd)]
pub enum VideoPreset {
    Placebo,
    VerySlow,
    Slower,
    Slow,
    Medium,
    Fast,
    Faster,
    VeryFast,
    SuperFast,
    UltraFast,
}

impl Default for VideoPreset {
    fn default() -> Self {
        VideoPreset::Placebo
    }
}

impl FromStr for VideoPreset {
    type Err = FFmpegError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "placebo" => Ok(VideoPreset::Placebo),
            "veryslow" => Ok(VideoPreset::VerySlow),
            "slower" => Ok(VideoPreset::Slower),
            "slow" => Ok(VideoPreset::Slow),
            "medium" => Ok(VideoPreset::Medium),
            "fast" => Ok(VideoPreset::Fast),
            "faster" => Ok(VideoPreset::Faster),
            "veryfast" => Ok(VideoPreset::VeryFast),
            "superfast" => Ok(VideoPreset::SuperFast),
            "ultrafast" => Ok(VideoPreset::UltraFast),
            _ => Err(FFmpegError::PresetUnknown {
                name: s.to_string(),
            }),
        }
    }
}

impl ToString for VideoPreset {
    fn to_string(&self) -> String {
        match &self {
            VideoPreset::Placebo => "placebo",
            VideoPreset::VerySlow => "veryslow",
            VideoPreset::Slower => "slower",
            VideoPreset::Slow => "slow",
            VideoPreset::Medium => "medium",
            VideoPreset::Fast => "fast",
            VideoPreset::Faster => "faster",
            VideoPreset::VeryFast => "veryfast",
            VideoPreset::SuperFast => "superfast",
            VideoPreset::UltraFast => "ultrafast",
        }
        .into()
    }
}