LiveKit C++ SDK
Real-time audio/video SDK for C++
Loading...
Searching...
No Matches
livekit::VideoFrame Class Reference

#include <video_frame.h>

Public Member Functions

 VideoFrame (int width, int height, VideoBufferType type, std::vector< std::uint8_t > data)
 
 VideoFrame (const VideoFrame &)=delete
 
VideoFrameoperator= (const VideoFrame &)=delete
 
 VideoFrame (VideoFrame &&) noexcept=default
 
VideoFrameoperator= (VideoFrame &&) noexcept=default
 
int width () const noexcept
 
int height () const noexcept
 
VideoBufferType type () const noexcept
 
std::uint8_t * data () noexcept
 
const std::uint8_t * data () const noexcept
 
std::size_t dataSize () const noexcept
 
std::vector< VideoPlaneInfoplaneInfos () const
 
VideoFrame convert (VideoBufferType dst, bool flip_y=false) const
 

Static Public Member Functions

static VideoFrame create (int width, int height, VideoBufferType type)
 

Static Protected Member Functions

static VideoFrame fromOwnedInfo (const proto::OwnedVideoBuffer &owned)
 

Friends

class VideoStream
 

Detailed Description

Public SDK representation of a video frame.

  • Owns its pixel buffer (std::vector<uint8_t>).
  • Developers can allocate and fill frames in C++ and pass them to the SDK.
  • The SDK can expose the backing memory to Rust via data_ptr + layout for the duration of a blocking FFI call (similar to AudioFrame).

Member Function Documentation

◆ convert()

VideoFrame livekit::VideoFrame::convert ( VideoBufferType  dst,
bool  flip_y = false 
) const

Convert this frame into another pixel format.

This uses the underlying FFI video_convert pipeline to transform the current frame into a new VideoFrame with the requested dst buffer type (e.g. ARGB → I420, BGRA → RGB24, etc.).

Parameters
dstDesired output format (see VideoBufferType).
flip_yIf true, the converted frame will be vertically flipped.
Returns
A new VideoFrame containing the converted image data.

Notes:

  • This function allocates a new buffer and copies pixel data; it does not modify the original frame.
  • This function performs a full CPU-based pixel conversion**. Depending on resolution and format, this may involve substantial computation (e.g., color-space transforms, planar repacking, vertical flipping). Avoid calling this inside tight real-time loops unless necessary.
  • Throws std::runtime_error if the FFI conversion fails or if the format combination is unsupported.

Typical usage: VideoFrame i420 = frame.convert(VideoBufferType::I420);

◆ create()

static VideoFrame livekit::VideoFrame::create ( int  width,
int  height,
VideoBufferType  type 
)
static

Allocate a new frame with the correct buffer size for the given format. Data is zero-initialized.

◆ planeInfos()

std::vector< VideoPlaneInfo > livekit::VideoFrame::planeInfos ( ) const

Compute plane layout for this frame (Y/U/V, UV, etc.), in terms of pointers & sizes relative to this frame's backing buffer.

For packed formats (ARGB, RGB24) this will be either 1 plane or empty.


The documentation for this class was generated from the following file: