How can i call "ffprobe -i video.mp4" with rust

I am a beginner and i search for the first functions i need.
So, how can i call a normal programm with rust like "ffprobe -i video.mp4"?

In the standard library there's Command (read also the module level doc) which should be enough for most uses. But you can find higher level libraries on crates.io.

fn main() {
   std::process::Command::new("ffprobe")
        .arg("-i")
        .arg("video.mp4")
        .status()
        .expect("process failed to execute");
}
1 Like

Thank you!
I had searched syscall, but I was not heard on "std :: process :: Command".
:slight_smile:

So, i have the next problem.
ffprobe -i video.mp4
put his output to error-out, not to std-out...

how can i catch it?

thise dosn't work:

fn main() {
    let a = std::process::Command::new("ffprobe")
        .arg("-i")
        .arg("video.mp4")
        .status()
        .expect("ffprobe konnte nicht ausgeführt werden");

    println!("================================================================================");
    println!("{}", a);
}

You’d want to use .output() instead of .status():

fn main() {
    let output = std::process::Command::new("ffprobe")
        .arg("-i")
        .arg("video.webm")
        .output()
        .expect("process failed to execute");
    println!("completed with {}", output.status);
    let s = String::from_utf8_lossy(&output.stderr);
    for line in s.lines() {
        if line.starts_with("    encoder") {
            println!("{}", &line);
        }
    }
}
1 Like

Thank you!
it works :slight_smile: