Skip to main content

BorrowedVideoFrame

Struct BorrowedVideoFrame 

Source
pub struct BorrowedVideoFrame<'buf> { /* private fields */ }
Expand description

A borrowed video frame that references external pixel data. Sender::send_video_async_copy copies its pixels and metadata into an owned frame; source buffers can be reused immediately after submission.

Fields are private to enforce safety invariants. Use Self::try_from_uncompressed for packed pixels, or Self::builder for explicit stride, metadata, and header options. Construction borrows without allocation and validates the entire supported uncompressed layout once.

Implementations§

Source§

impl<'buf> BorrowedVideoFrame<'buf>

Source

pub fn try_from_uncompressed( data: &'buf [u8], width: i32, height: i32, pixel_format: PixelFormat, frame_rate_n: i32, frame_rate_d: i32, ) -> Result<Self>

Create a borrowed video frame from an uncompressed pixel buffer.

This constructor validates that the buffer is large enough for the specified dimensions and pixel format, returning an error if validation fails. Width must be positive and even for every pixel format. Height must be positive, and must also be even for 4:2:0 formats.

§Arguments
  • data - Borrowed slice containing pixel data
  • width - Frame width in pixels
  • height - Frame height in pixels
  • pixel_format - Uncompressed pixel format (BGRA, UYVY, etc.)
  • frame_rate_n - Frame rate numerator (e.g., 60 for 60fps, 30000 for 29.97fps)
  • frame_rate_d - Frame rate denominator (e.g., 1 for 60fps, 1001 for 29.97fps)
§Errors

Returns Error::InvalidFrame if the buffer is too small for the specified format.

§Example
let buffer = vec![0u8; 1920 * 1080 * 4]; // BGRA buffer
let frame = BorrowedVideoFrame::try_from_uncompressed(
    &buffer,
    1920,
    1080,
    PixelFormat::BGRA,
    30,
    1
)?;
Source

pub fn builder( data: &'buf [u8], width: i32, height: i32, pixel_format: PixelFormat, ) -> BorrowedVideoFrameBuilder<'buf>

Configure a checked borrowed frame, including padded first-plane stride. Defaults match try_from_uncompressed, with a frame rate of 30/1. All validation occurs in BorrowedVideoFrameBuilder::build.

Source

pub fn try_to_owned(&self) -> Result<VideoFrame>

Copy this borrowed frame into a validated owned frame.

Active pixels are copied into tightly packed planes; row padding is skipped and the owned stride can shrink. Metadata is copied separately; no reference to the source is retained.

Source

pub fn width(&self) -> i32

Get the frame width in pixels.

Source

pub fn height(&self) -> i32

Get the frame height in pixels.

Source

pub fn pixel_format(&self) -> PixelFormat

Get the validated uncompressed pixel format.

Source

pub fn fourcc(&self) -> u32

Get the raw SDK FourCC value.

Source

pub fn frame_rate_n(&self) -> i32

Get the frame rate numerator.

Source

pub fn frame_rate_d(&self) -> i32

Get the frame rate denominator.

Source

pub fn picture_aspect_ratio(&self) -> f32

Get the picture aspect ratio.

Source

pub fn scan_type(&self) -> ScanType

Get the scan type.

Source

pub fn timecode(&self) -> i64

Get the timecode.

Source

pub fn data(&self) -> &[u8] ⓘ

Get a reference to the pixel data.

Source

pub fn line_stride_or_size(&self) -> LineStrideOrSize

Get the validated first-plane line stride.

Source

pub fn validated_data_len(&self) -> usize

Complete validated storage extent, including row padding.

Source

pub fn metadata(&self) -> Option<&str>

Get cached UTF-8 metadata text, preserving absent versus present-empty.

Source

pub fn timestamp(&self) -> i64

Get the timestamp.

Source

pub fn with_timecode(self, timecode: i64) -> Self

Set the timecode, in 100 ns units.

try_from_uncompressed leaves it at NDIlib_send_timecode_synthesize, which asks the SDK to make one up.

§Example
let buffer = vec![0u8; 1920 * 1080 * 2];
let frame = BorrowedVideoFrame::try_from_uncompressed(
    &buffer, 1920, 1080, PixelFormat::UYVY, 25, 1,
)?
.with_timecode(10_000_000);
assert_eq!(frame.timecode(), 10_000_000);
Source

pub fn with_picture_aspect_ratio(self, ratio: f32) -> Result<Self>

Set the picture aspect ratio, width over height as displayed; 0.0 means square pixels, whatever the resolution.

try_from_uncompressed assumes 16:9.

§Errors

Returns Error::InvalidFrame if ratio is negative or not finite.

Trait Implementations§

Source§

impl<'buf> From<&'buf VideoFrame> for BorrowedVideoFrame<'buf>

Source§

fn from(frame: &'buf VideoFrame) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'buf> Freeze for BorrowedVideoFrame<'buf>

§

impl<'buf> RefUnwindSafe for BorrowedVideoFrame<'buf>

§

impl<'buf> Send for BorrowedVideoFrame<'buf>

§

impl<'buf> Sync for BorrowedVideoFrame<'buf>

§

impl<'buf> Unpin for BorrowedVideoFrame<'buf>

§

impl<'buf> UnsafeUnpin for BorrowedVideoFrame<'buf>

§

impl<'buf> UnwindSafe for BorrowedVideoFrame<'buf>

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.