How libffmpeg locates ffmpeg and ffprobe binaries using environment variables and PATH
libffmpeg automatically discovers ffmpeg and ffprobe binaries on your system using a two-stage lookup process: environment variables first, then PATH search.
Validates that the path points to a valid executable using is_valid_executable() from the libwhich crate
If the environment variable is set but points to an invalid or non-executable file, the discovery will fail and NOT fall back to PATH search. Ensure the path is correct and executable.
From ~/workspace/source/libffmpeg/src/ffmpeg/error.rs:20-23:
#[error( "Unable to locate ffmpeg on your PATH, set LIBFFMPEG_FFMPEG_PATH to the binary, or update your PATH")]NotFound,
This error is returned when find_ffmpeg() returns None:From ~/workspace/source/libffmpeg/src/ffmpeg/slim.rs:24-26:
let ffmpeg_path = find_ffmpeg().ok_or(FfmpegError::NotFound).inspect_err( |e| tracing::error!(error =% e, error_context =? e, "ffmpeg binary not found"),)?;
If ffmpeg is already in your PATH, no configuration is needed:
use libffmpeg::ffmpeg::ffmpeg_slim;use tokio_util::sync::CancellationToken;// Automatically finds ffmpeg in PATHlet result = ffmpeg_slim(CancellationToken::new(), |cmd| { cmd.arg("-version");}).await?;
Set the environment variable before running your application:
# In your shellexport LIBFFMPEG_FFMPEG_PATH=/usr/local/bin/ffmpeg-customexport LIBFFMPEG_FFPROBE_PATH=/usr/local/bin/ffprobe-custom# Run your applicationcargo run
Or set it programmatically:
use std::env;// Set before calling any libffmpeg functionsenv::set_var("LIBFFMPEG_FFMPEG_PATH", "/opt/ffmpeg/bin/ffmpeg");env::set_var("LIBFFMPEG_FFPROBE_PATH", "/opt/ffmpeg/bin/ffprobe");// Now discovery will use the custom pathslet result = ffmpeg_slim(token, |cmd| { cmd.arg("-version");}).await?;
use libffmpeg::ffmpeg::find_ffmpeg;use libffmpeg::ffprobe::find_ffprobe;if let Some(ffmpeg_path) = find_ffmpeg() { println!("Using ffmpeg: {}", ffmpeg_path.display());} else { eprintln!("ffmpeg not found!");}if let Some(ffprobe_path) = find_ffprobe() { println!("Using ffprobe: {}", ffprobe_path.display());} else { eprintln!("ffprobe not found!");}
The find_ffmpeg() and find_ffprobe() functions are not exported in the public API by default. They are internal implementation details, but the same logic is used by all execution functions.
libffmpeg uses the tracing crate for logging. Enable trace-level logs to see discovery details:
use tracing_subscriber;tracing_subscriber::fmt() .with_max_level(tracing::Level::TRACE) .init();// Now you'll see discovery logslet result = ffmpeg_slim(token, |cmd| { cmd.arg("-version");}).await?;
Example log output:
TRACE libffmpeg::util::find: Looking for binary "ffmpeg" with env key "LIBFFMPEG_FFMPEG_PATH"INFO libffmpeg::ffmpeg::slim: Executing ffmpeg ffmpeg_path=/usr/bin/ffmpeg