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: i64Capture 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: u64Per-stream counter advanced once per delivered frame; a jump means frames were dropped.
width: u32§height: u32§stride: u32Bytes 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
impl VideoFrame
Sourcepub fn to_tight_bytes(&self) -> Option<Vec<u8>>
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 goneTrait Implementations§
Source§impl Clone for VideoFrame
impl Clone for VideoFrame
Source§fn clone(&self) -> VideoFrame
fn clone(&self) -> VideoFrame
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VideoFrame
impl Debug for VideoFrame
Source§impl PartialEq for VideoFrame
impl PartialEq for VideoFrame
Source§fn eq(&self, other: &VideoFrame) -> bool
fn eq(&self, other: &VideoFrame) -> bool
self and other values to be equal, and is used by ==.