use std::path::{Path, PathBuf};
use crate::command::FfmpegBinaryPaths;
use crate::error::{Error, Result};
#[derive(Clone, Debug)]
pub struct FfmpegLocator {
paths: FfmpegBinaryPaths,
}
impl FfmpegLocator {
pub fn system() -> Result<Self> {
Ok(Self {
paths: FfmpegBinaryPaths::auto()?,
})
}
pub fn with_paths(ffmpeg: impl Into<PathBuf>, ffprobe: impl Into<PathBuf>) -> Result<Self> {
let ffmpeg = ffmpeg.into();
let ffprobe = ffprobe.into();
if !ffmpeg.exists() {
return Err(Error::FFmpegNotFound {
suggestion: Some(format!("ffmpeg not found at {}", ffmpeg.display())),
});
}
if !ffprobe.exists() {
return Err(Error::FFmpegNotFound {
suggestion: Some(format!("ffprobe not found at {}", ffprobe.display())),
});
}
Ok(Self {
paths: FfmpegBinaryPaths::with_paths(ffmpeg, ffprobe),
})
}
pub fn from_paths(paths: FfmpegBinaryPaths) -> Self {
Self { paths }
}
pub fn binaries(&self) -> &FfmpegBinaryPaths {
&self.paths
}
pub fn ffmpeg(&self) -> &Path {
self.paths.ffmpeg()
}
pub fn ffprobe(&self) -> &Path {
self.paths.ffprobe()
}
}
pub fn system_locator() -> Result<FfmpegLocator> {
FfmpegLocator::system()
}