Skip to main content

ffmpeg_version_with_path

Function ffmpeg_version_with_path 

Source
pub fn ffmpeg_version_with_path<S: AsRef<OsStr>>(path: S) -> Result<String>
Expand description

Lower level variant of ffmpeg_version that exposes a customized path to the ffmpeg binary.

Examples found in repository?
examples/download_ffmpeg.rs (line 62)
2fn main() -> anyhow::Result<()> {
3  use ffmpeg_sidecar::{
4    command::ffmpeg_is_installed,
5    download::{
6      check_latest_version, download_ffmpeg_package, ffmpeg_download_url, unpack_ffmpeg,
7      unpack_ffmpeg_without_extras,
8    },
9    paths::sidecar_dir,
10    version::ffmpeg_version_with_path,
11  };
12  use std::env::{current_exe, var};
13
14  if ffmpeg_is_installed() {
15    println!("FFmpeg is already installed! 🎉");
16    println!("For demo purposes, we'll re-download and unpack it anyway.");
17    println!("TIP: Use `auto_download()` to skip manual customization.");
18  }
19
20  // Short version without customization:
21  // ```rust
22  // ffmpeg_sidecar::download::auto_download().unwrap();
23  // ```
24
25  // Checking the version number before downloading is actually not necessary,
26  // but it's a good way to check that the download URL is correct.
27  match check_latest_version() {
28    Ok(version) => println!("Latest available version: {version}"),
29    Err(_) => println!("Skipping version check on this platform."),
30  }
31
32  // These defaults will automatically select the correct download URL for your
33  // platform.
34  let download_url = ffmpeg_download_url()?;
35  let cli_arg = std::env::args().nth(1);
36  let destination = match cli_arg {
37    Some(arg) => resolve_relative_path(current_exe()?.parent().unwrap().join(arg)),
38    None => sidecar_dir()?,
39  };
40
41  // The built-in download function uses `reqwest` to download the package.
42  // For more advanced use cases like async streaming or download progress
43  // updates, you could replace this with your own download function.
44  println!("Downloading from: {download_url:?}");
45  let archive_path = download_ffmpeg_package(download_url, &destination)?;
46  println!("Downloaded package: {archive_path:?}");
47
48  // Extraction uses `tar` on all platforms (available in Windows since version 1803)
49  println!("Extracting...");
50  let keep_only_ffmpeg = var("KEEP_ONLY_FFMPEG")
51    .map(|value| value == "1" || value.eq_ignore_ascii_case("true"))
52    .unwrap_or(false);
53
54  if keep_only_ffmpeg {
55    println!("KEEP_ONLY_FFMPEG is set, skipping ffplay and ffprobe.");
56    unpack_ffmpeg_without_extras(&archive_path, &destination)?;
57  } else {
58    unpack_ffmpeg(&archive_path, &destination)?;
59  }
60
61  // Use the freshly installed FFmpeg to check the version number
62  let version = ffmpeg_version_with_path(destination.join("ffmpeg"))?;
63  println!("FFmpeg version: {version}");
64
65  println!("Done! 🏁");
66  Ok(())
67}