pub struct VideoFrame { /* private fields */ }Implementations§
Source§impl VideoFrame
impl VideoFrame
Sourcepub fn pixel_format(&self) -> PixelFormat
pub fn pixel_format(&self) -> PixelFormat
Get the supported 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 timecode(&self) -> i64
pub fn timecode(&self) -> i64
Get the timecode.
A value of zero is passed through to the SDK as its default timestamp behavior.
Sourcepub fn timestamp(&self) -> i64
pub fn timestamp(&self) -> i64
Get the timestamp.
A value of zero is passed through to the SDK as its default timestamp behavior.
Sourcepub fn line_stride_or_size(&self) -> LineStrideOrSize
pub fn line_stride_or_size(&self) -> LineStrideOrSize
Get the validated line stride or data size union field.
Sourcepub fn data_mut(&mut self) -> &mut [u8] ⓘ
pub fn data_mut(&mut self) -> &mut [u8] ⓘ
Get mutable access to the frame data without changing the validated layout.
Sourcepub fn replace_data(&mut self, data: Vec<u8>) -> Result<()>
pub fn replace_data(&mut self, data: Vec<u8>) -> Result<()>
Replace the owned frame data while preserving the validated layout.
§Errors
Returns Error::InvalidFrame if data is not exactly the validated
layout size.
Sourcepub fn set_metadata<S: Into<String>>(
&mut self,
metadata: Option<S>,
) -> Result<()>
pub fn set_metadata<S: Into<String>>( &mut self, metadata: Option<S>, ) -> Result<()>
Replace frame metadata.
§Errors
Returns Error::InvalidCString if metadata contains an interior NUL
byte, or Error::InvalidFrame if the emitted C string would exceed
the metadata size cap.
Sourcepub fn set_frame_rate(&mut self, numerator: i32, denominator: i32) -> Result<()>
pub fn set_frame_rate(&mut self, numerator: i32, denominator: i32) -> Result<()>
Set the frame rate.
§Errors
Returns Error::InvalidFrame if the numerator or denominator is not
positive.
Sourcepub fn set_picture_aspect_ratio(&mut self, ratio: f32) -> Result<()>
pub fn set_picture_aspect_ratio(&mut self, ratio: f32) -> Result<()>
Set the picture aspect ratio.
§Errors
Returns Error::InvalidFrame if ratio is not finite and positive.
Sourcepub fn encode_png(&self) -> Result<Vec<u8>>
pub fn encode_png(&self) -> Result<Vec<u8>>
Encode the video frame as PNG bytes.
This method encodes the frame to PNG format, automatically handling color format conversion from the NDI frame format (BGRA/RGBA/etc.) to PNG-compatible RGBA.
§Supported Formats
RGBA: Direct encoding when rows are tightly packedBGRA: Swaps red and blue channels and preserves alphaRGBX: Treats the fourth byte as padding and writes opaque alphaBGRX: Swaps red/blue and writes opaque alpha- Other formats: Returns an error (unsupported for now)
§Stride Handling
This method consumes active pixels row-by-row according to the frame’s validated line stride. Valid row padding is skipped.
§Errors
Returns an error if:
- The frame format is not RGBA/RGBX/BGRA/BGRX
- The frame uses data-size layout instead of line-stride layout
- The backing data length does not match the validated layout
- PNG encoding fails
§Example
let video_frame = receiver.video().capture(Duration::from_secs(5))?;
let png_bytes = video_frame.encode_png()?;
std::fs::write("frame.png", &png_bytes)?;Sourcepub fn encode_jpeg(&self, quality: u8) -> Result<Vec<u8>>
pub fn encode_jpeg(&self, quality: u8) -> Result<Vec<u8>>
Encode the video frame as JPEG bytes with the specified quality.
This method encodes the frame to JPEG format, automatically handling color format conversion from the NDI frame format to JPEG-compatible RGB.
§Arguments
quality- JPEG quality from 1 (lowest) to 100 (highest). Typical values are 80-95.
§Supported Formats
RGBA/RGBX: Emits RGBBGRA/BGRX: Swaps red/blue and emits RGB- Other formats: Returns an error (unsupported for now)
§Errors
Returns an error if:
- The frame format is not RGBA/RGBX/BGRA/BGRX
- The frame uses data-size layout instead of line-stride layout
- The backing data length does not match the validated layout
- The quality is outside
1..=100 - The dimensions exceed JPEG’s
u16width/height range - JPEG encoding fails
§Example
let video_frame = receiver.video().capture(Duration::from_secs(5))?;
let jpeg_bytes = video_frame.encode_jpeg(85)?;
std::fs::write("frame.jpg", &jpeg_bytes)?;Sourcepub fn encode_data_url(&self, format: ImageFormat) -> Result<String>
pub fn encode_data_url(&self, format: ImageFormat) -> Result<String>
Encode the video frame as a base64 data URL for embedding in HTML/JSON.
This produces a string in the format: data:image/png;base64,... or
data:image/jpeg;base64,... that can be directly used in HTML <img> tags
or stored in JSON.
§Arguments
format- The image format to use (PNG or JPEG with quality)
§Example
let video_frame = receiver.video().capture(Duration::from_secs(5))?;
// As PNG
let data_url = video_frame.encode_data_url(ImageFormat::Png)?;
println!("<img src=\"{}\">", data_url);
// As JPEG with quality 90
let data_url = video_frame.encode_data_url(ImageFormat::Jpeg(90))?;Sourcepub unsafe fn from_raw(c_frame: &NDIlib_video_frame_v2_t) -> Result<VideoFrame>
pub unsafe fn from_raw(c_frame: &NDIlib_video_frame_v2_t) -> Result<VideoFrame>
Creates a VideoFrame from a raw NDI video frame with owned data.
§Safety
This function assumes the given NDIlib_video_frame_v2_t is valid and correctly allocated.
This method copies the data, so the VideoFrame owns its data and can outlive the source.
Sourcepub fn builder() -> VideoFrameBuilder
pub fn builder() -> VideoFrameBuilder
Create a builder for configuring a video frame