Skip to main content

VideoFrame

Struct VideoFrame 

Source
pub struct VideoFrame {
    pub stream_time_ns: i64,
    pub sequence: u64,
    pub width: u32,
    pub height: u32,
    pub stride: u32,
    pub pixel_format: PixelFormat,
    pub color_space: Option<ColorSpace>,
    pub data: FrameData,
    pub damage: Option<Vec<Rect>>,
}
Expand description

One captured video frame with complete layout and timing metadata.

Fields§

§stream_time_ns: i64

Capture timestamp in nanoseconds, monotonic within a session and comparable with AudioFrame::stream_time_ns of the same session. The epoch is platform-dependent (boot time on macOS/Windows, process-relative on Linux).

§sequence: u64

Per-stream counter advanced once per delivered frame; a jump means frames were dropped.

§width: u32§height: u32§stride: u32

Bytes from the start of one row to the next in FrameData::Host.

§pixel_format: PixelFormat§color_space: Option<ColorSpace>§data: FrameData§damage: Option<Vec<Rect>>

Changed regions since the previous frame, when the backend knows.

Implementations§

Source§

impl VideoFrame

Source

pub fn to_tight_bytes(&self) -> Option<Vec<u8>>

Returns FrameData::Host bytes with row padding stripped, i.e. width * bytes_per_pixel bytes per row instead of stride.

stride can be wider than the tightly-packed row size (platform row alignment); copying data directly into something that assumes tight packing (a rawvideo pipe, an image encoder) silently skews every row after the first. Use this instead of touching data directly.

Returns None for non-FrameData::Host variants, or for pixel formats without a well-defined bytes-per-pixel (see PixelFormat::bytes_per_pixel).

§Examples
use pinray_core::{FrameData, PixelFormat, VideoFrame};

let (width, height, stride) = (2u32, 2u32, 12u32); // 4 padding bytes/row
let mut data = Vec::new();
for row in 0..height {
    data.extend(std::iter::repeat_n(row as u8, width as usize * 4));
    data.extend(std::iter::repeat_n(0xAA, (stride - width * 4) as usize));
}
let frame = VideoFrame {
    stream_time_ns: 0,
    sequence: 0,
    width,
    height,
    stride,
    pixel_format: PixelFormat::Bgra8888,
    color_space: None,
    data: FrameData::Host(data),
    damage: None,
};

let tight = frame.to_tight_bytes().unwrap();
assert_eq!(tight.len(), (width * height * 4) as usize);
assert!(tight.iter().all(|&b| b != 0xAA)); // padding is gone

Trait Implementations§

Source§

impl Clone for VideoFrame

Source§

fn clone(&self) -> VideoFrame

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VideoFrame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for VideoFrame

Source§

fn eq(&self, other: &VideoFrame) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for VideoFrame

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more