Skip to main content

DecodedFrame

Struct DecodedFrame 

Source
pub struct DecodedFrame { /* private fields */ }
Expand description

A frame a decoder returned, and whether every byte of its buffers, row padding included, is written.

Only this crate can say where a frame came from, so only it makes one: DecodedFrame::receive takes one from a decoder, and a hardware frame lease’s download copies one out. A frame from anywhere else goes to yuv_planes, which copies its samples.

Implementations§

Source§

impl DecodedFrame

Source

pub fn receive(decoder: &mut AVCodecContext) -> Result<Self, RsmpegError>

Takes the next frame decoder has ready, as AVCodecContext::receive_frame does.

§Errors

Returns what avcodec_receive_frame does: a drained or flushed decoder, or a decode failure.

Source

pub fn yuv_planes(&self) -> Result<Option<YuvPlanes>, BridgeError>

Hands over the planes of this frame, as yuv_planes does, but shares the frame’s buffer when every byte of it is written: each plane is then a view of the buffer, row padding included, and the buffer stays alive, unmodified, as long as a view does. A plane that cannot be shared, with a negative linesize or outside every buffer the frame references, is copied into tightly packed, forward rows.

§Errors

Returns an error for invalid dimensions, null planes, or linesizes shorter than their plane width.

Source

pub fn set_pts(&mut self, pts: i64)

Sets the frame’s presentation timestamp.

Source

pub fn into_frame(self) -> AVFrame

The frame itself, for a caller that takes ownership of it.

Methods from Deref<Target = AVFrame>§

Source

pub fn as_ptr(&self) -> *const AVFrame

Source

pub fn is_allocated(&self) -> bool

Return true if the data and buffer of current frame is allocated.

Source

pub fn ch_layout(&self) -> AVChannelLayoutRef<'_>

Get channel layout

Source

pub fn is_writable(&self) -> Result<bool, RsmpegError>

Check if the frame data is writable.

Source

pub fn image_get_buffer_size(&self, align: i32) -> Result<usize, RsmpegError>

Return the size in bytes of the amount of data required to store the image contained in the frame with the given linesize alignment.

The following fields must be set on frame before calling this function:

  • format
  • width
  • height
§Examples
// 10x10 pixels, 3 bytes per pixel, 30 bytes per line
let frame = AVFrameWithImage::new(AVImage::new(ffi::AV_PIX_FMT_RGB24, 10, 10, 1).unwrap());
// alignment 1: no padding
assert_eq!(frame.image_get_buffer_size(1).unwrap(), 30 * 10);
// alignment 8: each line padded to 32 bytes
assert_eq!(frame.image_get_buffer_size(8).unwrap(), 32 * 10);
Source

pub fn image_copy_to_buffer( &self, dst: &mut [u8], align: i32, ) -> Result<usize, RsmpegError>

Copy image data from an image frame into a slice with given linesize alignment.

The following fields must be set on frame before calling this function:

  • format
  • width
  • height

AVFrame::image_get_buffer_size can be used to compute the required size for the slice to fill.

Returns the amount of bytes written.

Hint: Linesize alignment is the alignment that each horizontal row of pixels will be padded to before being written. If you simply want the raw pixel values as a continuous slice, use an alignment of 1.

§Examples
// 10x10 pixels, 1 byte per pixel, 10 bytes per line
let frame = AVFrameWithImage::new(AVImage::new(ffi::AV_PIX_FMT_GRAY8, 10, 10, 1).unwrap());
const NOT_ZERO: u8 = 123;

// alignment 1: no padding
let size = frame.image_get_buffer_size(1).unwrap();
let mut buf = vec![NOT_ZERO; size];
assert_eq!(frame.image_copy_to_buffer(&mut buf, 1).unwrap(), 100);
assert_eq!(buf, &[0u8; 10 * 10]);

// alignment 8: each line padded to 16 bytes
let size = frame.image_get_buffer_size(8).unwrap();
let mut buf = vec![NOT_ZERO; size];
assert_eq!(frame.image_copy_to_buffer(&mut buf, 8).unwrap(), 160);
let chunks = buf.chunks_exact(16);
assert_eq!(chunks.len(), 10); // 10 lines
for chunk in chunks {
    assert_eq!(chunk.len(), 16); // 16 bytes per line
    assert!(chunk.starts_with(&[0u8; 10])); // 10 bytes of pixel data
    assert!(chunk.ends_with(&[NOT_ZERO; 6])); // 6 bytes of padding, not overwritten
}
Source

pub fn get_side_data( &'frame self, side_data_type: u32, ) -> Option<AVFrameSideDataRef<'frame>>

Trait Implementations§

Source§

impl Debug for DecodedFrame

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Deref for DecodedFrame

Source§

type Target = AVFrame

The resulting type after dereferencing.
Source§

fn deref(&self) -> &AVFrame

Dereferences the value.

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<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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.