ff_remux/error.rs
1//! Error type for remuxing operations.
2
3use ff_format::{ErrorSeverity, MediaError};
4use thiserror::Error;
5
6/// Errors that can occur during stream-copy remuxing (trim, audio replace /
7/// extract / add).
8#[derive(Error, Debug)]
9pub enum RemuxError {
10 /// A configuration value is missing or invalid.
11 #[error("invalid configuration: {reason}")]
12 InvalidConfig {
13 /// Human-readable description of the configuration problem.
14 reason: String,
15 },
16
17 /// A remux operation (trim, extract, replace, add) failed for a structural
18 /// reason (e.g. the input has no matching stream, or a mux/remux call failed).
19 #[error("remux operation failed: {reason}")]
20 OperationFailed {
21 /// Human-readable description of the failure.
22 reason: String,
23 },
24
25 /// An underlying `FFmpeg` function returned an error code.
26 #[error("ffmpeg error: {message} (code={code})")]
27 Ffmpeg {
28 /// Raw `FFmpeg` error code (negative integer). `0` when no numeric code is available.
29 code: i32,
30 /// Human-readable error message from `av_strerror` or an internal description.
31 message: String,
32 },
33
34 /// An I/O error occurred.
35 #[error("IO error: {0}")]
36 Io(#[from] std::io::Error),
37}
38
39impl RemuxError {
40 /// Create an error from a raw `FFmpeg` error code, resolving the message via
41 /// `av_strerror`.
42 pub(crate) fn from_ffmpeg_error(errnum: i32) -> Self {
43 RemuxError::Ffmpeg {
44 code: errnum,
45 message: ff_sys::av_error_string(errnum),
46 }
47 }
48}
49
50impl MediaError for RemuxError {
51 fn severity(&self) -> ErrorSeverity {
52 match self {
53 Self::Ffmpeg { .. } => ErrorSeverity::Other,
54 Self::InvalidConfig { .. } | Self::OperationFailed { .. } | Self::Io(_) => {
55 ErrorSeverity::Fatal
56 }
57 }
58 }
59}