Skip to main content

ImageDecoder

Struct ImageDecoder 

Source
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

Source

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.

Source

pub fn width(&self) -> u32

Returns the image width in pixels.

Source

pub fn height(&self) -> u32

Returns the image height in pixels.

Source

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.

Source

pub fn frames(&mut self) -> ImageFrameIterator<'_>

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.

Source

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.

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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.