pub fn open(path: impl AsRef<Path>) -> Result<MediaInfo, ProbeError>Expand description
Opens a media file and extracts its metadata.
This function opens the file at the given path using FFmpeg, reads the container
format information, and returns a MediaInfo struct containing all extracted
metadata.
§Arguments
path- Path to the media file to probe. Accepts anything that can be converted to aPath, including&str,String,PathBuf, etc.
§Returns
Returns Ok(MediaInfo) on success, or a ProbeError on failure.
§Errors
ProbeError::FileNotFoundif the file does not existProbeError::CannotOpenifFFmpegcannot open the fileProbeError::InvalidMediaif stream information cannot be readProbeError::Ioif there’s an I/O error accessing the file
§Examples
§Opening a Video File
use ff_probe::open;
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open by string path
let info = open("video.mp4")?;
// Or by Path
let path = Path::new("/path/to/video.mkv");
let info = open(path)?;
if let Some(video) = info.primary_video() {
println!("Resolution: {}x{}", video.width(), video.height());
}
Ok(())
}§Handling Errors
use ff_probe::{open, ProbeError};
// Non-existent file returns FileNotFound
let result = open("/this/file/does/not/exist.mp4");
assert!(matches!(result, Err(ProbeError::FileNotFound { .. })));