Skip to main content

VideoFrame

Struct VideoFrame 

Source
pub struct VideoFrame<P, E, D> { /* private fields */ }
Expand description

A decoded video frame.

Generic parameters:

  • P — pixel-format identifier (e.g. mediadecode_ffmpeg::PixelFormat).
  • E — backend-specific frame extras (HDR mastering display, RAW sensor metadata, picture type, …).
  • D — plane data buffer type. Each populated Plane<D> carries one plane’s bytes; D: AsRef<[u8]> at the use site (e.g. Bytes, &'a [u8], refcounted FFmpeg buffer).

width / height are the coded dimensions; visible_rect (when present) is the displayable subregion (FFmpeg crop / WebCodecs visibleRect / ProRes RAW CleanAperture).

plane_count is the number of populated entries in planes. Four slots cover every realistic format: NV12 = 2, YUV420P = 3, YUVA / packed-with-alpha = 4, packed RGB / Bayer CFA = 1.

Implementations§

Source§

impl<P, E, D> VideoFrame<P, E, D>

Source

pub const fn new( dimensions: Dimensions, pixel_format: P, planes: [Plane<D>; 4], plane_count: u8, extra: E, ) -> Self

Constructs a VideoFrame. Timestamps default to None, visible_rect to None, color to ColorInfo::UNSPECIFIED.

dimensions is the coded width/height pair (see Dimensions and Self::dimensions for the visible-vs- coded distinction).

§Panics

Panics if plane_count > 4. The fixed-size planes array has four slots; passing a larger plane_count would later trip the slice indexing inside Self::planes far from the construction site. Asserting here fails fast with a clear message instead. Prefer Self::try_new when plane_count can’t be statically proven <= 4.

Source

pub fn try_new( dimensions: Dimensions, pixel_format: P, planes: [Plane<D>; 4], plane_count: u8, extra: E, ) -> Result<Self, FrameError>

Fallible counterpart to Self::new. Returns FrameError::TooManyVideoPlanes when plane_count > 4 (the fixed plane array’s capacity) rather than panicking.

Not const fn — returning Result<Self, _> would require dropping the moved generic-typed planes / pixel_format / extra on the error branch, which the const evaluator can’t prove safe for arbitrary P / E / D.

Source

pub const fn pts(&self) -> Option<Timestamp>

Returns the presentation timestamp.

Source

pub const fn duration(&self) -> Option<Timestamp>

Returns the duration.

Source

pub const fn dimensions(&self) -> Dimensions

Returns the coded dimensions.

Source

pub const fn width(&self) -> u32

Returns the coded width.

Source

pub const fn height(&self) -> u32

Returns the coded height.

Source

pub const fn visible_rect(&self) -> Option<Rect>

Returns the visible / clean-aperture rectangle, if any.

Source

pub const fn pixel_format(&self) -> &P

Returns a reference to the pixel format identifier.

Source

pub const fn plane_count(&self) -> u8

Returns the populated plane count.

Source

pub fn planes(&self) -> &[Plane<D>]

Returns the populated planes as a slice.

Source

pub fn plane(&self, i: usize) -> Option<&Plane<D>>

Returns one plane by index, or None if out of range.

Source

pub const fn color(&self) -> ColorInfo

Returns the color metadata.

Source

pub const fn extra(&self) -> &E

Returns the backend extras.

Source

pub const fn extra_mut(&mut self) -> &mut E

Returns a mutable reference to the backend extras.

Source

pub const fn with_pts(self, v: Option<Timestamp>) -> Self

Sets the PTS (consuming builder).

Source

pub const fn with_duration(self, v: Option<Timestamp>) -> Self

Sets the duration (consuming builder).

Source

pub const fn with_visible_rect(self, v: Option<Rect>) -> Self

Sets the visible rect (consuming builder).

Source

pub const fn with_color(self, v: ColorInfo) -> Self

Sets the color metadata (consuming builder).

Source

pub const fn set_pts(&mut self, v: Option<Timestamp>) -> &mut Self

Sets the PTS in place.

Source

pub const fn set_duration(&mut self, v: Option<Timestamp>) -> &mut Self

Sets the duration in place.

Source

pub const fn set_visible_rect(&mut self, v: Option<Rect>) -> &mut Self

Sets the visible rect in place.

Source

pub const fn set_color(&mut self, v: ColorInfo) -> &mut Self

Sets the color metadata in place.

Auto Trait Implementations§

§

impl<P, E, D> Freeze for VideoFrame<P, E, D>
where P: Freeze, E: Freeze, D: Freeze,

§

impl<P, E, D> RefUnwindSafe for VideoFrame<P, E, D>

§

impl<P, E, D> Send for VideoFrame<P, E, D>
where P: Send, E: Send, D: Send,

§

impl<P, E, D> Sync for VideoFrame<P, E, D>
where P: Sync, E: Sync, D: Sync,

§

impl<P, E, D> Unpin for VideoFrame<P, E, D>
where P: Unpin, E: Unpin, D: Unpin,

§

impl<P, E, D> UnsafeUnpin for VideoFrame<P, E, D>

§

impl<P, E, D> UnwindSafe for VideoFrame<P, E, D>
where P: UnwindSafe, E: UnwindSafe, D: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.