简体   繁体   中英

How does Rust work with process arguments?

I'm really confused about Rust processes. I'm trying to call something like this:

ffmpeg -i path/to/test-video.webm -ab 160k -ac 2 -vn -f mp3 -

This should extract sound out of video and send it to stdout. So I've done this:

let sound: std::process::Output = Command::new("ffmpeg")
    .arg(format!("-i {}", args.input.to_str().unwrap()))
    .arg("-ab 160k")
    .arg("-ac 2")
    .arg("-vn")
    .arg("-f mp3")
    .arg("-")
    .stdout(Stdio::piped())
    .stdin(Stdio::inherit())
    .stderr(Stdio::inherit())
    .output()
    .unwrap();

But for some reason, this doesn't work. It prints this to stderr:

Unrecognized option 'i path/to/test-video.webm'.
Error splitting the argument list: Option not found

When I remove the slashes from args (so it looks like .arg(format,("i {}". ...)).arg("ab 160k")... , I get this:

Output file #0 does not contain any stream

I think I misunderstood how this works, but I tested it on other applications and it seemed to work the way I'm doing it now. What did I miss, how does Rust work with these arguments?

And just to be clear, I know about the ffmpeg crates, but they don't work for me for some reason, I can't even compile them.

try this

    let sound: std::process::Output = Command::new("ffmpeg")
        .arg("-i")
        .arg(args.input.to_str().unwrap())
        .arg("-ab")
        .arg("160k")
        .arg("-ac")
        .arg("2")
        .arg("-vn")
        .arg("-f")
        .arg("mp3")
        .arg("-")
        .stdout(Stdio::piped())
        .stdin(Stdio::inherit())
        .stderr(Stdio::inherit())
        .output()
        .unwrap();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM