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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//! Pixel and sample formats
/// Pixel format of a video frame.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum PixFmt {
/// Packed BGRA, 8 bits per channel.
Bgra,
/// Packed RGBA, 8 bits per channel.
Rgba,
/// Packed ARGB, 8 bits per channel.
Argb,
/// Packed ABGR, 8 bits per channel.
Abgr,
/// Packed BGRX, 8 bits per channel, the 4th byte is undefined.
Bgr0,
/// Packed RGBX, 8 bits per channel, the 4th byte is undefined.
Rgb0,
}
impl PixFmt {
/// Bytes one pixel occupies.
pub const fn bytes_per_pixel(self) -> usize {
match self {
Self::Bgra | Self::Rgba | Self::Argb | Self::Abgr | Self::Bgr0 | Self::Rgb0 => 4,
}
}
/// The matching ffmpeg `AVPixelFormat` id.
pub const fn as_ffmpeg_id(self) -> i32 {
match self {
Self::Argb => 25,
Self::Rgba => 26,
Self::Abgr => 27,
Self::Bgra => 28,
Self::Rgb0 => 119,
Self::Bgr0 => 121,
}
}
/// The format an ffmpeg `AVPixelFormat` id denotes, if it is one of these.
pub const fn from_ffmpeg_id(id: i32) -> Option<Self> {
match id {
25 => Some(Self::Argb),
26 => Some(Self::Rgba),
27 => Some(Self::Abgr),
28 => Some(Self::Bgra),
119 => Some(Self::Rgb0),
121 => Some(Self::Bgr0),
_ => None,
}
}
}
/// Sample format of an audio frame.
///
/// The `*P` variants are planar: one plane per channel, instead of channels interleaved.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum SampleFmt {
/// Unsigned 8 bits, interleaved.
U8,
/// Signed 16 bits, interleaved.
S16,
/// Signed 32 bits, interleaved.
S32,
/// 32 bit float, interleaved.
F32,
/// 64 bit float, interleaved.
F64,
/// Unsigned 8 bits, planar.
U8P,
/// Signed 16 bits, planar.
S16P,
/// Signed 32 bits, planar.
S32P,
/// 32 bit float, planar.
F32P,
/// 64 bit float, planar.
F64P,
}
impl SampleFmt {
/// Whether each channel gets its own plane.
pub const fn is_planar(self) -> bool {
match self {
Self::U8 | Self::S16 | Self::S32 | Self::F32 | Self::F64 => false,
Self::U8P | Self::S16P | Self::S32P | Self::F32P | Self::F64P => true,
}
}
/// Bytes one sample of one channel occupies.
pub const fn bytes_per_sample(self) -> usize {
match self {
Self::U8 | Self::U8P => 1,
Self::S16 | Self::S16P => 2,
Self::S32 | Self::S32P | Self::F32 | Self::F32P => 4,
Self::F64 | Self::F64P => 8,
}
}
/// The matching ffmpeg `AVSampleFormat` id.
pub const fn as_ffmpeg_id(self) -> i32 {
match self {
Self::U8 => 0,
Self::S16 => 1,
Self::S32 => 2,
Self::F32 => 3,
Self::F64 => 4,
Self::U8P => 5,
Self::S16P => 6,
Self::S32P => 7,
Self::F32P => 8,
Self::F64P => 9,
}
}
/// The format an ffmpeg `AVSampleFormat` id denotes, if it is one of these.
pub const fn from_ffmpeg_id(id: i32) -> Option<Self> {
match id {
0 => Some(Self::U8),
1 => Some(Self::S16),
2 => Some(Self::S32),
3 => Some(Self::F32),
4 => Some(Self::F64),
5 => Some(Self::U8P),
6 => Some(Self::S16P),
7 => Some(Self::S32P),
8 => Some(Self::F32P),
9 => Some(Self::F64P),
_ => None,
}
}
}