pub struct Yuv420pFrameBuffer { /* private fields */ }Expand description
A reusable FFmpeg YUV420P frame the caller writes into directly.
yuv420p_frame allocates a frame and copies three planes into it on
whichever thread calls it, which for an export is the encode worker. A
caller that can produce the pixels itself (a GPU readback packing straight
into encoder memory) wants the frame allocated once and rewritten, so
neither the allocation nor the copy happens per frame.
The buffer stays valid while FFmpeg holds a reference to it, which it
does between send_frame and the packet that consumes it.
Yuv420pFrameBuffer::begin_write is what makes reuse safe: it returns
the plane memory only once the buffer is no longer shared, copying it away
from FFmpeg if it still is.
Implementations§
Source§impl Yuv420pFrameBuffer
impl Yuv420pFrameBuffer
Sourcepub fn new(width: i32, height: i32) -> Result<Yuv420pFrameBuffer, BridgeError>
pub fn new(width: i32, height: i32) -> Result<Yuv420pFrameBuffer, BridgeError>
Allocates one reusable frame for this exact coded size.
§Errors
Returns an error for a non-positive size or a failed allocation.
Sourcepub const fn dimensions(&self) -> (usize, usize)
pub const fn dimensions(&self) -> (usize, usize)
Luma width and height in pixels.
Sourcepub fn begin_write(&mut self) -> Result<Yuv420pFramePlanes<'_>, BridgeError>
pub fn begin_write(&mut self) -> Result<Yuv420pFramePlanes<'_>, BridgeError>
Returns the plane memory to overwrite, after making the frame unshared.
§Errors
Returns an error when FFmpeg cannot make the buffer writable or its
planes are not laid out as this frame was allocated.
Sourcepub fn set_presentation(&mut self, pts: i64, time_base: AVRational)
pub fn set_presentation(&mut self, pts: i64, time_base: AVRational)
Stamps the presentation timestamp this frame will be encoded with.