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
impl DecodedFrame
Sourcepub fn receive(decoder: &mut AVCodecContext) -> Result<Self, RsmpegError>
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.
Sourcepub fn yuv_planes(&self) -> Result<Option<YuvPlanes>, BridgeError>
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.
Sourcepub fn into_frame(self) -> AVFrame
pub fn into_frame(self) -> AVFrame
The frame itself, for a caller that takes ownership of it.
Methods from Deref<Target = AVFrame>§
pub fn as_ptr(&self) -> *const AVFrame
Sourcepub fn is_allocated(&self) -> bool
pub fn is_allocated(&self) -> bool
Return true if the data and buffer of current frame is allocated.
Sourcepub fn ch_layout(&self) -> AVChannelLayoutRef<'_>
pub fn ch_layout(&self) -> AVChannelLayoutRef<'_>
Get channel layout
Sourcepub fn is_writable(&self) -> Result<bool, RsmpegError>
pub fn is_writable(&self) -> Result<bool, RsmpegError>
Check if the frame data is writable.
Sourcepub fn image_get_buffer_size(&self, align: i32) -> Result<usize, RsmpegError>
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);Sourcepub fn image_copy_to_buffer(
&self,
dst: &mut [u8],
align: i32,
) -> Result<usize, RsmpegError>
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
}