Skip to main content

FormatError

Enum FormatError 

Source
pub enum FormatError {
    InvalidPixelFormat {
        format: String,
    },
    InvalidSampleFormat {
        format: String,
    },
    InvalidTimestamp {
        pts: i64,
        time_base: Rational,
    },
    PlaneIndexOutOfBounds {
        index: usize,
        max: usize,
    },
    ConversionFailed {
        from: PixelFormat,
        to: PixelFormat,
    },
    AudioConversionFailed {
        from: SampleFormat,
        to: SampleFormat,
    },
    InvalidFrameData(String),
}
Expand description

Error type for format-related operations.

This is the main error type for the ff-format crate and is used for errors related to pixel formats, sample formats, timestamps, and format conversions.

§Error Variants

§Examples

use ff_format::{FormatError, PixelFormat, Rational};

// Create an invalid timestamp error
let error = FormatError::InvalidTimestamp {
    pts: -1,
    time_base: Rational::new(1, 90000),
};
assert!(error.to_string().contains("pts=-1"));

// Create a plane index out of bounds error
let error = FormatError::PlaneIndexOutOfBounds {
    index: 5,
    max: 3,
};
assert!(error.to_string().contains("out of bounds"));

Variants§

§

InvalidPixelFormat

Invalid or unrecognized pixel format string.

This error occurs when parsing a pixel format name that is not recognized or supported.

Fields

§format: String

The invalid pixel format string.

§

InvalidSampleFormat

Invalid or unrecognized sample format string.

This error occurs when parsing a sample format name that is not recognized or supported.

Fields

§format: String

The invalid sample format string.

§

InvalidTimestamp

Invalid timestamp value.

This error occurs when a timestamp has an invalid PTS value or incompatible time base.

Fields

§pts: i64

The PTS (Presentation Timestamp) value.

§time_base: Rational

The time base used for the timestamp.

§

PlaneIndexOutOfBounds

Plane index exceeds the number of available planes.

This error occurs when trying to access a plane that doesn’t exist in the frame. For example, accessing plane 3 of an RGB image that only has plane 0.

Fields

§index: usize

The requested plane index.

§max: usize

The maximum valid plane index.

§

ConversionFailed

Pixel format conversion failed.

This error occurs when attempting to convert between two pixel formats that is not supported or fails.

Fields

§from: PixelFormat

The source pixel format.

§to: PixelFormat

The target pixel format.

§

AudioConversionFailed

Audio sample format conversion failed.

This error occurs when attempting to convert between two audio sample formats that is not supported or fails.

Fields

§from: SampleFormat

The source sample format.

§to: SampleFormat

The target sample format.

§

InvalidFrameData(String)

Invalid or corrupted frame data.

This error occurs when frame data is invalid, corrupted, or doesn’t match the expected format parameters.

Implementations§

Source§

impl FormatError

Source

pub fn invalid_pixel_format(format: impl Into<String>) -> Self

Creates an InvalidPixelFormat error from a format string.

§Examples
use ff_format::FormatError;

let error = FormatError::invalid_pixel_format("unknown_format");
assert!(error.to_string().contains("unknown_format"));
Source

pub fn invalid_sample_format(format: impl Into<String>) -> Self

Creates an InvalidSampleFormat error from a format string.

§Examples
use ff_format::FormatError;

let error = FormatError::invalid_sample_format("unknown_format");
assert!(error.to_string().contains("unknown_format"));
Source

pub fn invalid_frame_data(reason: impl Into<String>) -> Self

Creates an InvalidFrameData error with a description.

§Examples
use ff_format::FormatError;

let error = FormatError::invalid_frame_data("buffer size mismatch");
assert!(error.to_string().contains("buffer size"));
Source

pub fn plane_out_of_bounds(index: usize, max: usize) -> Self

Creates a PlaneIndexOutOfBounds error.

§Examples
use ff_format::FormatError;

let error = FormatError::plane_out_of_bounds(5, 3);
assert!(error.to_string().contains("5"));
assert!(error.to_string().contains("3"));
Source

pub fn conversion_failed(from: PixelFormat, to: PixelFormat) -> Self

Creates a ConversionFailed error for pixel format conversion.

§Examples
use ff_format::{FormatError, PixelFormat};

let error = FormatError::conversion_failed(PixelFormat::Yuv420p, PixelFormat::Rgba);
assert!(error.to_string().contains("Yuv420p"));
assert!(error.to_string().contains("Rgba"));
Source

pub fn audio_conversion_failed(from: SampleFormat, to: SampleFormat) -> Self

Creates an AudioConversionFailed error for sample format conversion.

§Examples
use ff_format::{FormatError, SampleFormat};

let error = FormatError::audio_conversion_failed(SampleFormat::I16, SampleFormat::F32);
assert!(error.to_string().contains("I16"));
assert!(error.to_string().contains("F32"));
Source

pub fn invalid_timestamp(pts: i64, time_base: Rational) -> Self

Creates an InvalidTimestamp error.

§Examples
use ff_format::{FormatError, Rational};

let error = FormatError::invalid_timestamp(-1, Rational::new(1, 90000));
assert!(error.to_string().contains("-1"));

Trait Implementations§

Source§

impl Clone for FormatError

Source§

fn clone(&self) -> FormatError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FormatError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for FormatError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for FormatError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for FormatError

Source§

fn eq(&self, other: &FormatError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for FormatError

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.