Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Run An External Command In Rust

This is a basic example using ffprobe which gets a string back (after chomping off the newline)

rust
use std::process::Command;

fn main() {
    let args: Vec<&str> = vec![
        "-v",
        "error",
        "-select_streams",
        "v:0",
        "-count_packets",
        "-show_entries",
        "stream=nb_read_packets",
        "-of",
        "csv=p=0",
        "some/path.mp4",
    ];
    let cmd_output = Command::new("ffprobe").args(args).output().unwrap();
    let frame_count_string = String::from_utf8(cmd_output.stdout).unwrap();
    let frame_count_str = frame_count_string.as_str().trim();
    dbg!(frame_count_str);
}
results full