use std::future::Future;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FfmpegErrorKind {
OutOfSpace,
Other,
}
#[derive(Debug, thiserror::Error)]
#[error("{reason}")]
pub struct FfmpegError {
kind: FfmpegErrorKind,
reason: String,
}
impl FfmpegError {
pub fn new(reason: impl Into<String>) -> Self {
Self {
kind: FfmpegErrorKind::Other,
reason: reason.into(),
}
}
pub fn out_of_space(reason: impl Into<String>) -> Self {
Self {
kind: FfmpegErrorKind::OutOfSpace,
reason: reason.into(),
}
}
pub fn kind(&self) -> FfmpegErrorKind {
self.kind
}
pub fn is_out_of_space(&self) -> bool {
self.kind == FfmpegErrorKind::OutOfSpace
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WebpEncodeSettings {
pub quality: u8,
pub max_fps: u32,
pub max_width: u32,
pub lossless: bool,
pub compression: bool,
}
impl Default for WebpEncodeSettings {
fn default() -> Self {
Self {
quality: 70,
max_fps: 24,
max_width: 720,
lossless: false,
compression: true,
}
}
}
pub trait Ffmpeg {
fn wav_to_flac(&self, wav: &[u8]) -> impl Future<Output = Result<Vec<u8>, FfmpegError>> + Send;
fn mp4_to_webp(
&self,
mp4: &[u8],
settings: WebpEncodeSettings,
) -> impl Future<Output = Result<Vec<u8>, FfmpegError>> + Send;
}