v_frame
v_frame provides data structures and utilities for handling YUV video frames. Originally developed as part of the rav1e video encoder, v_frame has been extracted into a standalone crate for broader use across the Rust AV ecosystem.
Features
- Type-safe pixel handling: Generic
Pixeltrait supporting both 8-bit (u8) and high bit-depth (u16) video - Support for common subsampling formats: YUV 4:2:0, 4:2:2, 4:4:4, and monochrome
- Performant API: Efficient row-based and pixel-based data access
- SIMD-friendly data alignment: Plane data is aligned to at least 64 bytes on most targets
no_stdsupport: Does not depend on the standard library (allocis required however)- WebAssembly support: Works in both browser (
wasm32-unknown-unknown) and WASI environments
Installation
Run cargo add v_frame or add this to your Cargo.toml:
[]
= "0.6"
The Pixel Trait
v_frame is built around a generic Pixel trait that abstracts the two possible underlying data types:
u8for 8-bit videou16for high bit-depth video (9-16 bits)
The API prevents mismatches between declared bit depth and pixel type.
Usage
Creating a Frame
use ;
// 10-bit 4K UHD frame
let frame = new
.
.unwrap;
Adding padding pixels
use ;
let mut builder = new;
// Add 16 pixels of padding on all sides for block-based algorithms
builder.luma_padding_left;
builder.luma_padding_right;
builder.luma_padding_top;
builder.luma_padding_bottom;
let frame = builder..unwrap;
Working with Plane Data
use ;
let mut frame = new
.
.unwrap;
// Access a specific row
if let Some = frame.y_plane.row_mut
// Iterate over all pixels in the plane
for pixel_row in frame.y_plane.rows
no_std support
This crate does not depend on the standard library std but does require alloc to allocate memory for Plane<T> data.
Users linking against std don't have to do anything. If you want to use this crate without std, you need to setup and configure a global allocator. The Embedded Rust Book might be helpful.
WebAssembly Support
v_frame works in WebAssembly environments:
# Build for browser environments
# Build for WASI
Documentation
Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
License
v_frame is licensed under the BSD 2-Clause License. See LICENSE for details.