Skip to main content

DecodeError

Enum DecodeError 

Source
pub enum DecodeError {
    FileNotFound {
        path: PathBuf,
    },
    NoVideoStream {
        path: PathBuf,
    },
    NoAudioStream {
        path: PathBuf,
    },
    UnsupportedCodec {
        codec: String,
    },
    DecodingFailed {
        timestamp: Option<Duration>,
        reason: String,
    },
    SeekFailed {
        target: Duration,
        reason: String,
    },
    HwAccelUnavailable {
        accel: HardwareAccel,
    },
    EndOfStream,
    Ffmpeg(String),
    Io(Error),
}
Expand description

Errors that can occur during decoding operations.

This enum covers all error conditions that may arise when opening, configuring, or decoding media files.

§Error Categories

Variants§

§

FileNotFound

File was not found at the specified path.

This error occurs when attempting to open a file that doesn’t exist.

Fields

§path: PathBuf

Path that was not found.

§

NoVideoStream

No video stream exists in the media file.

This error occurs when trying to decode video from a file that only contains audio or other non-video streams.

Fields

§path: PathBuf

Path to the media file.

§

NoAudioStream

No audio stream exists in the media file.

This error occurs when trying to decode audio from a file that only contains video or other non-audio streams.

Fields

§path: PathBuf

Path to the media file.

§

UnsupportedCodec

The codec is not supported by this decoder.

This may occur for uncommon or proprietary codecs that are not included in the FFmpeg build.

Fields

§codec: String

Name of the unsupported codec.

§

DecodingFailed

Decoding operation failed at a specific point.

This can occur due to corrupted data, unexpected stream format, or internal decoder errors.

Fields

§timestamp: Option<Duration>

Timestamp where decoding failed (if known).

§reason: String

Reason for the failure.

§

SeekFailed

Seek operation failed.

Seeking may fail for various reasons including corrupted index, seeking beyond file bounds, or stream format limitations.

Fields

§target: Duration

Target position of the seek.

§reason: String

Reason for the failure.

§

HwAccelUnavailable

Requested hardware acceleration is not available.

This error occurs when a specific hardware accelerator is requested but the system doesn’t support it. Consider using HardwareAccel::Auto for automatic fallback.

Fields

§accel: HardwareAccel

The unavailable hardware acceleration type.

§

EndOfStream

End of stream has been reached.

This is returned when attempting to decode past the end of the file. It’s a normal condition that indicates all frames have been decoded.

§

Ffmpeg(String)

FFmpeg internal error.

This wraps errors from the underlying FFmpeg library that don’t fit into other categories.

§

Io(Error)

I/O error during file operations.

This wraps standard I/O errors such as permission denied, disk full, or network errors for remote files.

Implementations§

Source§

impl DecodeError

Source

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

Creates a new DecodeError::DecodingFailed with the given reason.

§Arguments
  • reason - Description of why decoding failed.
§Examples
use ff_decode::DecodeError;

let error = DecodeError::decoding_failed("Corrupted frame data");
assert!(error.to_string().contains("Corrupted frame data"));
assert!(error.is_recoverable());
Source

pub fn decoding_failed_at( timestamp: Duration, reason: impl Into<String>, ) -> Self

Creates a new DecodeError::DecodingFailed with timestamp and reason.

§Arguments
  • timestamp - The timestamp where decoding failed.
  • reason - Description of why decoding failed.
§Examples
use ff_decode::DecodeError;
use std::time::Duration;

let error = DecodeError::decoding_failed_at(
    Duration::from_secs(30),
    "Invalid packet size"
);
assert!(error.to_string().contains("30s"));
assert!(error.is_recoverable());
Source

pub fn seek_failed(target: Duration, reason: impl Into<String>) -> Self

Creates a new DecodeError::SeekFailed.

§Arguments
  • target - The target position of the failed seek.
  • reason - Description of why the seek failed.
§Examples
use ff_decode::DecodeError;
use std::time::Duration;

let error = DecodeError::seek_failed(
    Duration::from_secs(60),
    "Index not found"
);
assert!(error.to_string().contains("60s"));
assert!(error.is_recoverable());
Source

pub fn ffmpeg(message: impl Into<String>) -> Self

Creates a new DecodeError::Ffmpeg.

§Arguments
  • message - The FFmpeg error message.
§Examples
use ff_decode::DecodeError;

let error = DecodeError::ffmpeg("AVERROR_INVALIDDATA");
assert!(error.to_string().contains("AVERROR_INVALIDDATA"));
Source

pub fn is_eof(&self) -> bool

Returns true if this error indicates end of stream.

§Examples
use ff_decode::DecodeError;

assert!(DecodeError::EndOfStream.is_eof());
assert!(!DecodeError::decoding_failed("test").is_eof());
Source

pub fn is_recoverable(&self) -> bool

Returns true if this error is recoverable.

Recoverable errors are those where the decoder can continue operating after the error, such as corrupted frames that can be skipped.

§Examples
use ff_decode::DecodeError;
use std::time::Duration;

// Decoding failures are recoverable
assert!(DecodeError::decoding_failed("test").is_recoverable());

// Seek failures are recoverable
assert!(DecodeError::seek_failed(Duration::from_secs(1), "test").is_recoverable());

// End of stream is not recoverable
assert!(!DecodeError::EndOfStream.is_recoverable());
Source

pub fn is_fatal(&self) -> bool

Returns true if this error is fatal.

Fatal errors indicate that the decoder cannot continue and must be recreated or the file reopened.

§Examples
use ff_decode::DecodeError;
use std::path::PathBuf;

// File not found is fatal
assert!(DecodeError::FileNotFound { path: PathBuf::new() }.is_fatal());

// Unsupported codec is fatal
assert!(DecodeError::UnsupportedCodec { codec: "test".to_string() }.is_fatal());

// End of stream is not fatal
assert!(!DecodeError::EndOfStream.is_fatal());

Trait Implementations§

Source§

impl Debug for DecodeError

Source§

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

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

impl Display for DecodeError

Source§

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

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

impl Error for DecodeError

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 From<Error> for DecodeError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

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> 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.