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
impl FfmpegError
Sourcepub fn new(operation: &'static str, message: impl Into<String>) -> Self
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 }pub fn with_path(self, path: impl Into<String>) -> Self
pub fn with_backend(self, backend: GpuBackend) -> Self
pub fn with_codec(self, codec: VideoCodec) -> Self
pub fn with_stream_index(self, stream_index: usize) -> Self
Trait Implementations§
Source§impl Clone for FfmpegError
impl Clone for FfmpegError
Source§fn clone(&self) -> FfmpegError
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FfmpegError
impl Debug for FfmpegError
Source§impl Display for FfmpegError
impl Display for FfmpegError
Source§impl Error for FfmpegError
impl Error for FfmpegError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl PartialEq for FfmpegError
impl PartialEq for FfmpegError
Source§fn eq(&self, other: &FfmpegError) -> bool
fn eq(&self, other: &FfmpegError) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for FfmpegError
impl StructuralPartialEq for FfmpegError
Auto Trait Implementations§
impl Freeze for FfmpegError
impl RefUnwindSafe for FfmpegError
impl Send for FfmpegError
impl Sync for FfmpegError
impl Unpin for FfmpegError
impl UnsafeUnpin for FfmpegError
impl UnwindSafe for FfmpegError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more