#[non_exhaustive]pub enum PixelFormat {
Show 13 variants
Rgb24,
Rgba,
Bgr24,
Bgra,
Yuv420p,
Yuv422p,
Yuv444p,
Nv12,
Nv21,
Yuv420p10le,
P010le,
Gray8,
Other(u32),
}Expand description
Pixel format for video frames.
This enum represents various pixel formats used in video processing.
It is designed to cover the most common formats used in video editing
while remaining extensible via the Other variant.
§Format Categories
- Packed RGB: Data stored contiguously (Rgb24, Rgba, Bgr24, Bgra)
- Planar YUV: Separate planes for Y, U, V components (Yuv420p, Yuv422p, Yuv444p)
- Semi-planar: Y plane + interleaved UV (Nv12, Nv21)
- High bit depth: 10-bit formats for HDR content (Yuv420p10le, P010le)
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Rgb24
24-bit RGB (8:8:8) - 3 bytes per pixel
Rgba
32-bit RGBA (8:8:8:8) - 4 bytes per pixel with alpha
Bgr24
24-bit BGR (8:8:8) - 3 bytes per pixel, reversed channel order
Bgra
32-bit BGRA (8:8:8:8) - 4 bytes per pixel with alpha, reversed channel order
Yuv420p
YUV 4:2:0 planar - most common video format (H.264, etc.)
Yuv422p
YUV 4:2:2 planar - higher chroma resolution
Yuv444p
YUV 4:4:4 planar - full chroma resolution
Nv12
Y plane + interleaved UV - common in hardware decoders
Nv21
Y plane + interleaved VU - Android camera format
Yuv420p10le
10-bit YUV 4:2:0 planar - HDR content
P010le
10-bit semi-planar NV12 - HDR hardware decoding
Gray8
8-bit grayscale
Other(u32)
Unknown or unsupported format with FFmpeg’s AVPixelFormat value
Implementations§
Source§impl PixelFormat
impl PixelFormat
Sourcepub const fn name(&self) -> &'static str
pub const fn name(&self) -> &'static str
Returns the format name as a human-readable string.
§Examples
use ff_format::PixelFormat;
assert_eq!(PixelFormat::Yuv420p.name(), "yuv420p");
assert_eq!(PixelFormat::Rgba.name(), "rgba");Sourcepub const fn num_planes(&self) -> usize
pub const fn num_planes(&self) -> usize
Returns the number of planes for this format.
- Packed formats (RGB, RGBA, etc.) have 1 plane
- Planar YUV formats have 3 planes (Y, U, V)
- Semi-planar formats (NV12, NV21) have 2 planes (Y, UV)
- Grayscale has 1 plane
§Examples
use ff_format::PixelFormat;
assert_eq!(PixelFormat::Rgba.num_planes(), 1);
assert_eq!(PixelFormat::Yuv420p.num_planes(), 3);
assert_eq!(PixelFormat::Nv12.num_planes(), 2);Sourcepub const fn plane_count(&self) -> usize
pub const fn plane_count(&self) -> usize
Alias for num_planes for API compatibility.
§Examples
use ff_format::PixelFormat;
assert_eq!(PixelFormat::Yuv420p.plane_count(), 3);Sourcepub const fn is_packed(&self) -> bool
pub const fn is_packed(&self) -> bool
Returns true if this is a packed format (single plane with interleaved components).
Packed formats store all color components contiguously in memory, making them suitable for direct rendering but less efficient for video compression.
§Examples
use ff_format::PixelFormat;
assert!(PixelFormat::Rgba.is_packed());
assert!(!PixelFormat::Yuv420p.is_packed());Sourcepub const fn is_planar(&self) -> bool
pub const fn is_planar(&self) -> bool
Returns true if this is a planar format (separate planes for each component).
Planar formats store each color component in a separate memory region, which is more efficient for video codecs and some GPU operations.
Note: Semi-planar formats (NV12, NV21, P010le) are considered planar as they have multiple planes, even though UV is interleaved.
§Examples
use ff_format::PixelFormat;
assert!(PixelFormat::Yuv420p.is_planar());
assert!(PixelFormat::Nv12.is_planar()); // Semi-planar is also planar
assert!(!PixelFormat::Rgba.is_planar());Sourcepub const fn has_alpha(&self) -> bool
pub const fn has_alpha(&self) -> bool
Returns true if this format has an alpha (transparency) channel.
§Examples
use ff_format::PixelFormat;
assert!(PixelFormat::Rgba.has_alpha());
assert!(PixelFormat::Bgra.has_alpha());
assert!(!PixelFormat::Rgb24.has_alpha());
assert!(!PixelFormat::Yuv420p.has_alpha());Sourcepub const fn is_rgb(&self) -> bool
pub const fn is_rgb(&self) -> bool
Returns true if this is an RGB-based format.
§Examples
use ff_format::PixelFormat;
assert!(PixelFormat::Rgb24.is_rgb());
assert!(PixelFormat::Rgba.is_rgb());
assert!(PixelFormat::Bgra.is_rgb()); // BGR is still RGB family
assert!(!PixelFormat::Yuv420p.is_rgb());Sourcepub const fn is_yuv(&self) -> bool
pub const fn is_yuv(&self) -> bool
Returns true if this is a YUV-based format.
§Examples
use ff_format::PixelFormat;
assert!(PixelFormat::Yuv420p.is_yuv());
assert!(PixelFormat::Nv12.is_yuv());
assert!(!PixelFormat::Rgba.is_yuv());Sourcepub const fn bits_per_pixel(&self) -> Option<usize>
pub const fn bits_per_pixel(&self) -> Option<usize>
Returns the bits per pixel for packed formats.
For planar formats, this returns None because the concept of
“bits per pixel” doesn’t apply directly - use bytes_per_pixel
to get the average bytes per pixel instead.
§Examples
use ff_format::PixelFormat;
assert_eq!(PixelFormat::Rgb24.bits_per_pixel(), Some(24));
assert_eq!(PixelFormat::Rgba.bits_per_pixel(), Some(32));
assert_eq!(PixelFormat::Yuv420p.bits_per_pixel(), None);Sourcepub const fn bytes_per_pixel(&self) -> usize
pub const fn bytes_per_pixel(&self) -> usize
Returns the average bytes per pixel.
For packed formats, this is exact. For planar YUV formats, this returns the average considering subsampling:
- YUV 4:2:0: 1.5 bytes/pixel (12 bits)
- YUV 4:2:2: 2 bytes/pixel (16 bits)
- YUV 4:4:4: 3 bytes/pixel (24 bits)
Note: For formats with non-integer bytes per pixel (like Yuv420p),
this rounds up to the nearest byte.
§Examples
use ff_format::PixelFormat;
assert_eq!(PixelFormat::Rgba.bytes_per_pixel(), 4);
assert_eq!(PixelFormat::Rgb24.bytes_per_pixel(), 3);
assert_eq!(PixelFormat::Yuv420p.bytes_per_pixel(), 2); // Actually 1.5, rounded up
assert_eq!(PixelFormat::Yuv444p.bytes_per_pixel(), 3);Sourcepub const fn is_high_bit_depth(&self) -> bool
pub const fn is_high_bit_depth(&self) -> bool
Returns true if this is a high bit depth format (> 8 bits per component).
§Examples
use ff_format::PixelFormat;
assert!(PixelFormat::Yuv420p10le.is_high_bit_depth());
assert!(PixelFormat::P010le.is_high_bit_depth());
assert!(!PixelFormat::Yuv420p.is_high_bit_depth());Trait Implementations§
Source§impl Clone for PixelFormat
impl Clone for PixelFormat
Source§fn clone(&self) -> PixelFormat
fn clone(&self) -> PixelFormat
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PixelFormat
impl Debug for PixelFormat
Source§impl Default for PixelFormat
impl Default for PixelFormat
Source§fn default() -> Self
fn default() -> Self
Returns the default pixel format.
The default is PixelFormat::Yuv420p as it’s the most common
format used in video encoding.