pub struct Decoder<R: Read> { /* private fields */ }Expand description
A streaming YUV4MPEG2 decoder.
Owns one reusable frame buffer sized at header parse time.
Decoder::read_frame fills it and returns borrowed plane slices.
Implementations§
Source§impl<R: Read> Decoder<R>
impl<R: Read> Decoder<R>
Sourcepub fn new(reader: R) -> Result<Self, Error>
pub fn new(reader: R) -> Result<Self, Error>
Reads and parses the stream header with the default Limits.
Sourcepub fn with_limits(reader: R, limits: Limits) -> Result<Self, Error>
pub fn with_limits(reader: R, limits: Limits) -> Result<Self, Error>
Reads and parses the stream header, enforcing limits before the
frame buffer is allocated.
EOF while reading the stream header is Error::EndOfStream. A
wrong magic or malformed parameter is Error::Parse.
Sourcepub fn framerate(&self) -> Ratio
pub fn framerate(&self) -> Ratio
Frame rate. Defaults to 25:1 when the F tag is absent. The default
stays out of Decoder::raw_params.
Sourcepub fn pixel_aspect(&self) -> Ratio
pub fn pixel_aspect(&self) -> Ratio
Pixel (sample) aspect ratio, where 0:0 means unknown.
Sourcepub fn interlace(&self) -> Interlace
pub fn interlace(&self) -> Interlace
Interlacing mode, Interlace::Unknown when the I tag is absent.
Sourcepub fn colorspace(&self) -> Colorspace
pub fn colorspace(&self) -> Colorspace
The stream colorspace, plain 4:2:0 8-bit when the C tag is absent.
Sourcepub fn raw_params(&self) -> &[u8] ⓘ
pub fn raw_params(&self) -> &[u8] ⓘ
Stream header parameter bytes after the "YUV4MPEG2 " prefix,
verbatim, LF excluded. Feed to
EncoderBuilder::raw_params for
a byte-exact re-encode.
Sourcepub fn plane_sizes(&self) -> [usize; 3]
pub fn plane_sizes(&self) -> [usize; 3]
Per-plane byte sizes [Y, U, V]. Chroma entries are 0 for mono.
Sourcepub fn read_frame(&mut self) -> Result<FrameRef<'_>, Error>
pub fn read_frame(&mut self) -> Result<FrameRef<'_>, Error>
Borrows the next frame. Planes point into the decoder’s reusable
internal buffer, so each call reuses the same storage. The
counting-allocator test tests/zero_alloc.rs pins the decode loop
at zero heap allocations.
Returns Error::EndOfStream at a clean end (EOF exactly where the
next FRAME magic would start) and Error::Truncated when EOF
falls inside a frame header or payload.
Sourcepub fn frame_bytes(&self) -> usize
pub fn frame_bytes(&self) -> usize
The frame byte count implied by the header (sum of plane sizes).