Skip to main content

VideoFrame

Struct VideoFrame 

Source
pub struct VideoFrame { /* private fields */ }

Implementations§

Source§

impl VideoFrame

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 supported pixel format.

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.

A value of zero is passed through to the SDK as its default timestamp behavior.

Source

pub fn timestamp(&self) -> i64

Get the timestamp.

A value of zero is passed through to the SDK as its default timestamp behavior.

Source

pub fn line_stride_or_size(&self) -> LineStrideOrSize

Get the validated line stride or data size union field.

Source

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

Get the frame data.

Source

pub fn data_mut(&mut self) -> &mut [u8]

Get mutable access to the frame data without changing the validated layout.

Source

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.

Source

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

Get frame metadata as UTF-8 text, if present.

Source

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.

Source

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.

Source

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.

Source

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 packed
  • BGRA: Swaps red and blue channels and preserves alpha
  • RGBX: Treats the fourth byte as padding and writes opaque alpha
  • BGRX: 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)?;
Source

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 RGB
  • BGRA / 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 u16 width/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)?;
Source

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))?;
Source

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.

Source

pub fn builder() -> VideoFrameBuilder

Create a builder for configuring a video frame

Trait Implementations§

Source§

impl Debug for VideoFrame

Source§

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

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

impl Default for VideoFrame

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for VideoFrame

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
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§

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.