Skip to main content

ff_encode/
container.rs

1//! Container format definitions.
2
3/// Container format for output file.
4///
5/// The container format is usually auto-detected from the file extension,
6/// but can be explicitly specified if needed.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum Container {
10    /// MP4 / `QuickTime`
11    Mp4,
12
13    /// `WebM`
14    WebM,
15
16    /// Matroska
17    Mkv,
18
19    /// AVI
20    Avi,
21
22    /// MOV
23    Mov,
24
25    /// FLAC (lossless audio container)
26    Flac,
27
28    /// OGG (audio container for Vorbis/Opus)
29    Ogg,
30}
31
32impl Container {
33    /// Get `FFmpeg` format name.
34    #[must_use]
35    pub const fn as_str(self) -> &'static str {
36        match self {
37            Self::Mp4 => "mp4",
38            Self::WebM => "webm",
39            Self::Mkv => "matroska",
40            Self::Avi => "avi",
41            Self::Mov => "mov",
42            Self::Flac => "flac",
43            Self::Ogg => "ogg",
44        }
45    }
46
47    /// Get default file extension.
48    #[must_use]
49    pub const fn default_extension(self) -> &'static str {
50        match self {
51            Self::Mp4 => "mp4",
52            Self::WebM => "webm",
53            Self::Mkv => "mkv",
54            Self::Avi => "avi",
55            Self::Mov => "mov",
56            Self::Flac => "flac",
57            Self::Ogg => "ogg",
58        }
59    }
60}
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_container_as_str() {
68        assert_eq!(Container::Mp4.as_str(), "mp4");
69        assert_eq!(Container::WebM.as_str(), "webm");
70        assert_eq!(Container::Mkv.as_str(), "matroska");
71    }
72
73    #[test]
74    fn test_container_extension() {
75        assert_eq!(Container::Mp4.default_extension(), "mp4");
76        assert_eq!(Container::WebM.default_extension(), "webm");
77        assert_eq!(Container::Mkv.default_extension(), "mkv");
78        assert_eq!(Container::Flac.default_extension(), "flac");
79        assert_eq!(Container::Ogg.default_extension(), "ogg");
80    }
81
82    #[test]
83    fn flac_as_str_should_return_flac() {
84        assert_eq!(Container::Flac.as_str(), "flac");
85    }
86
87    #[test]
88    fn ogg_as_str_should_return_ogg() {
89        assert_eq!(Container::Ogg.as_str(), "ogg");
90    }
91}