Function ffmpeg_version_with_path

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

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

Examples found in repository?
examples/download_ffmpeg.rs (line 54)
5async fn main() -> anyhow::Result<()> {
6  use async_ffmpeg_sidecar::{
7    command::ffmpeg_is_installed,
8    download::{check_latest_version, download_ffmpeg_package, ffmpeg_download_url, unpack_ffmpeg},
9    paths::sidecar_dir,
10    version::ffmpeg_version_with_path,
11  };
12  use std::env::current_exe;
13
14  if ffmpeg_is_installed().await {
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().await {
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  tokio::fs::create_dir_all(&destination).await?;
46  let archive_path = download_ffmpeg_package(download_url, &destination).await?;
47  println!("Downloaded package: {:?}", archive_path);
48
49  // Extraction uses `tar` on all platforms (available in Windows since version 1803)
50  println!("Extracting...");
51  unpack_ffmpeg(&archive_path, &destination).await?;
52
53  // Use the freshly installed FFmpeg to check the version number
54  let version = ffmpeg_version_with_path(destination.join("ffmpeg"))
55    .await
56    .context("error running ffmpeg")?;
57  println!("FFmpeg version: {}", version);
58
59  println!("Done! 🏁");
60  Ok(())
61}