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
26impl Container {
27    /// Get `FFmpeg` format name.
28    #[must_use]
29    pub const fn as_str(self) -> &'static str {
30        match self {
31            Self::Mp4 => "mp4",
32            Self::WebM => "webm",
33            Self::Mkv => "matroska",
34            Self::Avi => "avi",
35            Self::Mov => "mov",
36        }
37    }
38
39    /// Get default file extension.
40    #[must_use]
41    pub const fn default_extension(self) -> &'static str {
42        match self {
43            Self::Mp4 => "mp4",
44            Self::WebM => "webm",
45            Self::Mkv => "mkv",
46            Self::Avi => "avi",
47            Self::Mov => "mov",
48        }
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_container_as_str() {
58        assert_eq!(Container::Mp4.as_str(), "mp4");
59        assert_eq!(Container::WebM.as_str(), "webm");
60        assert_eq!(Container::Mkv.as_str(), "matroska");
61    }
62
63    #[test]
64    fn test_container_extension() {
65        assert_eq!(Container::Mp4.default_extension(), "mp4");
66        assert_eq!(Container::WebM.default_extension(), "webm");
67        assert_eq!(Container::Mkv.default_extension(), "mkv");
68    }
69}