繁体   English   中英

Rust 如何与进程 arguments 一起工作?

[英]How does Rust work with process arguments?

我真的很困惑 Rust 进程。 我正在尝试这样调用:

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

这应该从视频中提取声音并将其发送到标准输出。 所以我这样做了:

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();

但由于某种原因,这不起作用。 它将此打印到 stderr:

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

当我从 args 中删除斜线时(所以它看起来像.arg(format,("i {}". ...)).arg("ab 160k")... ,我得到这个:

Output file #0 does not contain any stream

我想我误解了它是如何工作的,但我在其他应用程序上测试过它,它似乎按照我现在的方式工作。 我错过了什么,Rust 如何与这些 arguments 一起使用?

需要说明的是,我知道 ffmpeg 箱子,但出于某种原因它们对我不起作用,我什至无法编译它们。

尝试这个

    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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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