pub struct ImageDecoder { /* private fields */ }Expand description
Decodes a single still image into a VideoFrame.
Supports common image formats: JPEG, PNG, BMP, TIFF, WebP.
§Construction
Use ImageDecoder::open() to create a builder, then call
ImageDecoderBuilder::build():
use ff_decode::ImageDecoder;
let frame = ImageDecoder::open("photo.png").build()?.decode()?;
println!("{}x{}", frame.width(), frame.height());§Frame Decoding
The image can be decoded as a single frame or via an iterator:
// Single frame (consuming)
let frame = decoder.decode()?;
// Via iterator (for API consistency with VideoDecoder / AudioDecoder)
for frame in decoder.frames() {
let frame = frame?;
}Implementations§
Source§impl ImageDecoder
impl ImageDecoder
Sourcepub fn open(path: impl AsRef<Path>) -> ImageDecoderBuilder
pub fn open(path: impl AsRef<Path>) -> ImageDecoderBuilder
Creates a builder for the specified image file path.
§Note
This method does not validate that the file exists or is a valid image.
Validation occurs when ImageDecoderBuilder::build() is called.
Sourcepub fn decode_one(&mut self) -> Result<Option<VideoFrame>, DecodeError>
pub fn decode_one(&mut self) -> Result<Option<VideoFrame>, DecodeError>
Decodes the image frame.
Returns Ok(Some(frame)) on the first call, then Ok(None) on
subsequent calls (the underlying FFmpeg context is consumed on first
decode).
§Errors
Returns DecodeError if FFmpeg fails to decode the image.
Sourcepub fn frames(
&mut self,
) -> impl Iterator<Item = Result<VideoFrame, DecodeError>> + '_
pub fn frames( &mut self, ) -> impl Iterator<Item = Result<VideoFrame, DecodeError>> + '_
Returns an iterator that yields the single decoded image frame.
This method exists for API consistency with VideoDecoder and
AudioDecoder. The iterator yields at most one item.
Sourcepub fn decode(self) -> Result<VideoFrame, DecodeError>
pub fn decode(self) -> Result<VideoFrame, DecodeError>
Decodes the image, consuming self and returning the VideoFrame.
This is a convenience wrapper around decode_one
for the common single-frame use-case.
§Errors
Returns DecodeError if the image cannot be decoded or was already
decoded.