ffmpeg_sidecar/
ffprobe.rs1use crate::command::BackgroundCommand;
4use anyhow::Context;
5use std::{env::current_exe, ffi::OsStr, path::PathBuf};
6use std::{
7 path::Path,
8 process::{Command, Stdio},
9};
10
11pub fn ffprobe_path() -> PathBuf {
15 let default = Path::new("ffprobe").to_path_buf();
16 match ffprobe_sidecar_path() {
17 Ok(sidecar_path) => match sidecar_path.exists() {
18 true => sidecar_path,
19 false => default,
20 },
21 Err(_) => default,
22 }
23}
24
25pub fn ffprobe_sidecar_path() -> anyhow::Result<PathBuf> {
30 let mut path = current_exe()?
31 .parent()
32 .context("Can't get parent of current_exe")?
33 .join("ffprobe");
34 if cfg!(windows) {
35 path.set_extension("exe");
36 }
37 Ok(path)
38}
39
40pub fn ffprobe_version() -> anyhow::Result<String> {
42 ffprobe_version_with_path(ffprobe_path())
43}
44
45pub fn ffprobe_version_with_path<S: AsRef<OsStr>>(path: S) -> anyhow::Result<String> {
48 let output = Command::new(&path)
49 .arg("-version")
50 .create_no_window()
51 .output()?;
52
53 Ok(String::from_utf8(output.stdout)?)
56}
57
58pub fn ffprobe_is_installed() -> bool {
62 Command::new(ffprobe_path())
63 .create_no_window()
64 .arg("-version")
65 .stderr(Stdio::null())
66 .stdout(Stdio::null())
67 .status()
68 .map(|s| s.success())
69 .unwrap_or_else(|_| false)
70}