Skip to main content

FfmpegError

Struct FfmpegError 

Source
pub struct FfmpegError {
    pub operation: &'static str,
    pub path: Option<String>,
    pub code: Option<i32>,
    pub message: String,
    pub backend: Option<GpuBackend>,
    pub codec: Option<VideoCodec>,
    pub stream_index: Option<usize>,
}

Fields§

§operation: &'static str§path: Option<String>§code: Option<i32>§message: String§backend: Option<GpuBackend>§codec: Option<VideoCodec>§stream_index: Option<usize>

Implementations§

Source§

impl FfmpegError

Source

pub fn new(operation: &'static str, message: impl Into<String>) -> Self

Examples found in repository?
examples/decode_file.rs (lines 113-116)
102fn receive_frame(
103    decoder: &mut VideoDecoder,
104    mode: DecodeMode,
105    receive: ReceiveMode,
106    cuda: Option<&mut CudaRgbaState>,
107) -> lumen_ffmpeg::Result<Option<usize>> {
108    match receive {
109        ReceiveMode::Rgba => Ok(decoder.receive_rgba_frame()?.map(|frame| frame.data.len())),
110        ReceiveMode::CudaRgba => match decoder.receive_gpu_frame()? {
111            Some(frame) => {
112                let Some(cuda) = cuda else {
113                    return Err(lumen_ffmpeg::FfmpegError::new(
114                        "decode_file",
115                        "cuda-rgba receive mode requires a CUDA conversion state",
116                    ));
117                };
118                cuda.convert(&frame)?;
119                Ok(Some(frame.estimated_rgba_bytes() as usize))
120            }
121            None => Ok(None),
122        },
123        ReceiveMode::Gpu => match mode {
124            DecodeMode::Cpu => Ok(decoder.receive_cpu_frame()?.map(|frame| frame.data.len())),
125            DecodeMode::Gpu(_) => Ok(decoder.receive_gpu_frame()?.map(|_| 0)),
126        },
127    }
128}
129
130#[derive(Debug, Clone, Copy)]
131enum ReceiveMode {
132    Rgba,
133    Gpu,
134    CudaRgba,
135}
136
137#[cfg(all(feature = "cuda", target_os = "linux"))]
138struct CudaRgbaState {
139    converter: lumen_ffmpeg::CudaNv12ToRgbaConverter<'static>,
140    destination: lumen_ffmpeg::CudaDeviceAllocation<'static>,
141    _context: lumen_ffmpeg::CudaContext<'static>,
142}
143
144#[cfg(all(feature = "cuda", target_os = "linux"))]
145impl CudaRgbaState {
146    fn new(
147        receive: ReceiveMode,
148        width: u32,
149        height: u32,
150    ) -> Result<Option<Self>, Box<dyn std::error::Error>> {
151        if !matches!(receive, ReceiveMode::CudaRgba) {
152            return Ok(None);
153        }
154        let driver = Box::leak(Box::new(CudaDriver::load()?));
155        let context = driver.create_primary_context()?;
156        let converter = driver.create_nv12_to_rgba_converter(&context)?;
157        let destination = driver.allocate_rgba_frame(width, height)?;
158        Ok(Some(Self {
159            converter,
160            destination,
161            _context: context,
162        }))
163    }
164
165    fn convert(&self, frame: &GpuVideoFrame) -> lumen_ffmpeg::Result<()> {
166        let GpuVideoFrame::Cuda(frame) = frame else {
167            return Err(lumen_ffmpeg::FfmpegError::new(
168                "decode_file",
169                "cuda-rgba receive mode requires CUDA decoded frames",
170            ));
171        };
172        self.converter
173            .convert(frame, &self.destination)
174            .map_err(|error| lumen_ffmpeg::FfmpegError::new("nv12_to_rgba8", error))
175    }
176}
177
178#[cfg(not(all(feature = "cuda", target_os = "linux")))]
179struct CudaRgbaState;
180
181#[cfg(not(all(feature = "cuda", target_os = "linux")))]
182impl CudaRgbaState {
183    fn new(
184        receive: ReceiveMode,
185        _width: u32,
186        _height: u32,
187    ) -> Result<Option<Self>, Box<dyn std::error::Error>> {
188        if matches!(receive, ReceiveMode::CudaRgba) {
189            return Err(
190                "cuda-rgba receive mode requires a Linux build with the cuda feature".into(),
191            );
192        }
193        Ok(None)
194    }
195
196    fn convert(&self, _frame: &GpuVideoFrame) -> lumen_ffmpeg::Result<()> {
197        Err(lumen_ffmpeg::FfmpegError::new(
198            "decode_file",
199            "cuda-rgba receive mode requires a Linux build with the cuda feature",
200        ))
201    }
Source

pub fn with_path(self, path: impl Into<String>) -> Self

Source

pub fn with_backend(self, backend: GpuBackend) -> Self

Source

pub fn with_codec(self, codec: VideoCodec) -> Self

Source

pub fn with_stream_index(self, stream_index: usize) -> Self

Trait Implementations§

Source§

impl Clone for FfmpegError

Source§

fn clone(&self) -> FfmpegError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FfmpegError

Source§

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

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

impl Display for FfmpegError

Source§

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

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

impl Error for FfmpegError

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 FfmpegError

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Eq for FfmpegError

Source§

impl StructuralPartialEq for FfmpegError

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.