pub fn ffmpeg_is_installed() -> boolExpand description
Verify whether ffmpeg is installed on the system. This will return true if there is an ffmpeg binary in the PATH, or in the same directory as the Rust executable.
Examples found in repository?
examples/download_ffmpeg_with_progress.rs (line 12)
9fn main() -> anyhow::Result<()> {
10 use ffmpeg_sidecar::command::ffmpeg_is_installed;
11
12 if ffmpeg_is_installed() {
13 println!("FFmpeg is already installed! 🎉");
14 println!("For demo purposes, we'll re-download and unpack it anyway.");
15 println!(
16 "TIP: Use `auto_download_with_progress(progress_callback)` to skip manual customization."
17 );
18 }
19
20 let progress_callback = |e: FfmpegDownloadProgressEvent| match e {
21 FfmpegDownloadProgressEvent::Starting => {
22 println!("Starting download...");
23 }
24 FfmpegDownloadProgressEvent::Downloading {
25 downloaded_bytes,
26 total_bytes,
27 } => {
28 print!(
29 "\rDownloaded {:.1}/{:.1} mB ",
30 downloaded_bytes as f64 / 1024.0 / 1024.0,
31 total_bytes as f64 / 1024.0 / 1024.0
32 );
33 std::io::stdout().flush().unwrap();
34 }
35 FfmpegDownloadProgressEvent::UnpackingArchive => {
36 println!("\nUnpacking archive...");
37 }
38 FfmpegDownloadProgressEvent::Done => {
39 println!("Ffmpeg downloaded successfully!")
40 }
41 };
42
43 force_download_with_progress(progress_callback)?;
44
45 let version = ffmpeg_version()?;
46 println!("FFmpeg version: {version}");
47 Ok(())
48}
49
50#[cfg(feature = "download_ffmpeg")]
51pub fn force_download_with_progress(
52 progress_callback: impl Fn(FfmpegDownloadProgressEvent),
53) -> anyhow::Result<()> {
54 use ffmpeg_sidecar::{command::ffmpeg_is_installed, paths::sidecar_dir};
55 use std::env::var;
56
57 progress_callback(FfmpegDownloadProgressEvent::Starting);
58 let download_url = ffmpeg_download_url()?;
59 let destination = sidecar_dir()?;
60 let archive_path =
61 download_ffmpeg_package_with_progress(download_url, &destination, |e| progress_callback(e))?;
62 progress_callback(FfmpegDownloadProgressEvent::UnpackingArchive);
63 let keep_only_ffmpeg = var("KEEP_ONLY_FFMPEG")
64 .map(|value| value == "1" || value.eq_ignore_ascii_case("true"))
65 .unwrap_or(false);
66
67 if keep_only_ffmpeg {
68 println!("KEEP_ONLY_FFMPEG is set, skipping ffplay and ffprobe.");
69 unpack_ffmpeg_without_extras(&archive_path, &destination)?;
70 } else {
71 unpack_ffmpeg(&archive_path, &destination)?;
72 }
73 progress_callback(FfmpegDownloadProgressEvent::Done);
74
75 if !ffmpeg_is_installed() {
76 anyhow::bail!("FFmpeg failed to install, please install manually.");
77 }
78
79 Ok(())
80}More examples
examples/download_ffmpeg.rs (line 14)
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}