1use std::path::{Path, PathBuf};
4
5use crate::command::FfmpegBinaryPaths;
6use crate::error::{Error, Result};
7
8#[derive(Clone, Debug)]
10pub struct FfmpegLocator {
11 paths: FfmpegBinaryPaths,
12}
13
14impl FfmpegLocator {
15 pub fn system() -> Result<Self> {
17 Ok(Self {
18 paths: FfmpegBinaryPaths::auto()?,
19 })
20 }
21
22 pub fn with_paths(ffmpeg: impl Into<PathBuf>, ffprobe: impl Into<PathBuf>) -> Result<Self> {
24 let ffmpeg = ffmpeg.into();
25 let ffprobe = ffprobe.into();
26 if !ffmpeg.exists() {
27 return Err(Error::FFmpegNotFound {
28 suggestion: Some(format!("ffmpeg not found at {}", ffmpeg.display())),
29 });
30 }
31 if !ffprobe.exists() {
32 return Err(Error::FFmpegNotFound {
33 suggestion: Some(format!("ffprobe not found at {}", ffprobe.display())),
34 });
35 }
36 Ok(Self {
37 paths: FfmpegBinaryPaths::with_paths(ffmpeg, ffprobe),
38 })
39 }
40
41 pub fn from_paths(paths: FfmpegBinaryPaths) -> Self {
43 Self { paths }
44 }
45
46 pub fn binaries(&self) -> &FfmpegBinaryPaths {
48 &self.paths
49 }
50
51 pub fn ffmpeg(&self) -> &Path {
53 self.paths.ffmpeg()
54 }
55
56 pub fn ffprobe(&self) -> &Path {
58 self.paths.ffprobe()
59 }
60}
61
62pub fn system_locator() -> Result<FfmpegLocator> {
64 FfmpegLocator::system()
65}