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>
impl<'buf> BorrowedVideoFrame<'buf>
Sourcepub fn try_from_uncompressed(
data: &'buf [u8],
width: i32,
height: i32,
pixel_format: PixelFormat,
frame_rate_n: i32,
frame_rate_d: i32,
) -> Result<Self>
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 datawidth- Frame width in pixelsheight- Frame height in pixelspixel_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
)?;Sourcepub fn builder(
data: &'buf [u8],
width: i32,
height: i32,
pixel_format: PixelFormat,
) -> BorrowedVideoFrameBuilder<'buf>
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.
Sourcepub fn try_to_owned(&self) -> Result<VideoFrame>
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.
Sourcepub fn pixel_format(&self) -> PixelFormat
pub fn pixel_format(&self) -> PixelFormat
Get the validated uncompressed pixel format.
Sourcepub fn frame_rate_n(&self) -> i32
pub fn frame_rate_n(&self) -> i32
Get the frame rate numerator.
Sourcepub fn frame_rate_d(&self) -> i32
pub fn frame_rate_d(&self) -> i32
Get the frame rate denominator.
Sourcepub fn picture_aspect_ratio(&self) -> f32
pub fn picture_aspect_ratio(&self) -> f32
Get the picture aspect ratio.
Sourcepub fn line_stride_or_size(&self) -> LineStrideOrSize
pub fn line_stride_or_size(&self) -> LineStrideOrSize
Get the validated first-plane line stride.
Sourcepub fn validated_data_len(&self) -> usize
pub fn validated_data_len(&self) -> usize
Complete validated storage extent, including row padding.
Sourcepub fn metadata(&self) -> Option<&str>
pub fn metadata(&self) -> Option<&str>
Get cached UTF-8 metadata text, preserving absent versus present-empty.
Sourcepub fn with_timecode(self, timecode: i64) -> Self
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);Sourcepub fn with_picture_aspect_ratio(self, ratio: f32) -> Result<Self>
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.