Skip to main content

rskit_media/encoding/
format.rs

1//! Container/file format identifiers and well-known constants.
2
3use std::sync::Arc;
4
5use serde::{Deserialize, Serialize};
6
7/// An open container/file format identifier.
8///
9/// # Examples
10///
11/// ```rust
12/// use rskit_media::format::{self, Format};
13///
14/// let mp4 = Format::new(format::MP4);
15/// let custom = Format::new("my_container");
16/// ```
17#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
18pub struct Format(Arc<str>);
19
20impl Format {
21    /// Create a new format identifier.
22    pub fn new(id: impl Into<Arc<str>>) -> Self {
23        Self(id.into())
24    }
25
26    /// The format identifier string.
27    pub fn id(&self) -> &str {
28        &self.0
29    }
30}
31
32impl std::fmt::Display for Format {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        f.write_str(&self.0)
35    }
36}
37
38// ── Video containers ─────────────────────────────────────────────────
39
40/// MPEG-4 Part 14.
41pub const MP4: &str = "mp4";
42/// Matroska.
43pub const MKV: &str = "mkv";
44/// WebM.
45pub const WEBM: &str = "webm";
46/// Audio Video Interleave.
47pub const AVI: &str = "avi";
48/// QuickTime.
49pub const MOV: &str = "mov";
50/// Flash Video.
51pub const FLV: &str = "flv";
52/// MPEG Transport Stream.
53pub const TS: &str = "ts";
54/// MPEG-4 Video.
55pub const M4V: &str = "m4v";
56/// Windows Media Video.
57pub const WMV: &str = "wmv";
58
59// ── Audio containers ─────────────────────────────────────────────────
60
61/// MP3 file.
62pub const MP3: &str = "mp3";
63/// Waveform Audio.
64pub const WAV: &str = "wav";
65/// Free Lossless Audio Codec file.
66pub const FLAC: &str = "flac";
67/// Ogg container.
68pub const OGG: &str = "ogg";
69/// AAC file.
70pub const AAC: &str = "aac";
71/// MPEG-4 Audio.
72pub const M4A: &str = "m4a";
73/// Windows Media Audio file.
74pub const WMA: &str = "wma";
75/// Opus file.
76pub const OPUS: &str = "opus";
77
78// ── Image formats ────────────────────────────────────────────────────
79
80/// PNG image.
81pub const PNG: &str = "png";
82/// JPEG image.
83pub const JPEG: &str = "jpeg";
84/// WebP image.
85pub const WEBP: &str = "webp";
86/// GIF image.
87pub const GIF: &str = "gif";
88/// BMP image.
89pub const BMP: &str = "bmp";
90/// TIFF image.
91pub const TIFF: &str = "tiff";
92/// SVG image.
93pub const SVG: &str = "svg";
94/// AVIF image.
95pub const AVIF: &str = "avif";
96/// HEIF image.
97pub const HEIF: &str = "heif";
98
99// ── Subtitle formats ─────────────────────────────────────────────────
100
101/// SubRip.
102pub const SRT: &str = "srt";
103/// WebVTT.
104pub const VTT: &str = "vtt";
105/// Advanced SubStation Alpha.
106pub const ASS: &str = "ass";