pub struct DecodedFrame { /* private fields */ }Expand description
A decoded frame, and whether every byte of its buffers, row padding included, is written.
Only this crate constructs one; frames from elsewhere go to yuv_planes.
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.
§Errors
Returns what avcodec_receive_frame does for a drained decoder or a decode failure.
Sourcepub fn yuv_planes(&self) -> Result<Option<YuvPlanes>, BridgeError>
pub fn yuv_planes(&self) -> Result<Option<YuvPlanes>, BridgeError>
Like yuv_planes, but shares the frame’s buffer when it is fully written. Planes with a
negative linesize or outside the frame’s buffers are still copied.
§Errors
Returns an error for invalid dimensions, null planes, or linesizes shorter than the plane width.
Sourcepub fn into_frame(self) -> AVFrame
pub fn into_frame(self) -> AVFrame
Takes ownership of the frame.
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
}