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.
Trait Implementations§
Auto Trait Implementations§
impl !Sync for Yuv420pFrameBuffer
impl Freeze for Yuv420pFrameBuffer
impl RefUnwindSafe for Yuv420pFrameBuffer
impl Send for Yuv420pFrameBuffer
impl Unpin for Yuv420pFrameBuffer
impl UnsafeUnpin for Yuv420pFrameBuffer
impl UnwindSafe for Yuv420pFrameBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more