Skip to main content

Yuv420pFrameBuffer

Struct Yuv420pFrameBuffer 

Source
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

Source

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.

Source

pub const fn dimensions(&self) -> (usize, usize)

Luma width and height in pixels.

Source

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.

Source

pub fn set_presentation(&mut self, pts: i64, time_base: AVRational)

Stamps the presentation timestamp this frame will be encoded with.

Source

pub const fn frame(&self) -> &AVFrame

The frame to hand to an encoder.

Source

pub const fn size(&self) -> (usize, usize)

Coded luma dimensions this buffer was allocated for.

Trait Implementations§

Source§

impl Debug for Yuv420pFrameBuffer

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,