简体   繁体   English

Java ProcessBuilder ffmpeg管道

[英]java processbuilder ffmpeg pipe

i try to run ffmpeg out java. 我尝试将ffmpeg运行出java。 here my code: 这是我的代码:

String[] temp = {"ffmpeg\\ffmpeg.exe","-i","input_track.ac3","-threads","0","-af","volume=volume="0.0"dB","-acodec","pcm_s32le","-ac","6","-ar","48000","-f","wav","-","|","ffmpeg\\fdkaac","--ignorelength","-m","1","-o","ouput_track.aac","-"};

ProcessBuilder pb = new ProcessBuilder(temp);
Process p = pb.start();
int ev = 0;
if (p.waitFor() != 0)
{
   ev = p.exitValue();
}

i try the comand at windows cmd, here have a problem with "|" 我在Windows cmd上尝试了comand,这里的“ |”有问题 at the ffmpeg command line. 在ffmpeg命令行上。

maybe someone say my fould? 也许有人说我的想法?

best regards 最好的祝福

This question is similar to How to make pipes work with Runtime.exec()? 这个问题类似于如何使管道与Runtime.exec()一起使用? ... except that it is for Windows. ...除了适用于Windows。

The problem is essentially the same: the exec methods don't understand shell syntax such as pipes, input or output direction and so on. 问题本质上是相同的: exec方法不了解shell语法,例如管道,输入或输出方向等。 The solution is essentially the same too: exec the appropriate shell and get that to handle the shell syntax. 解决方案在本质上也相同:执行适当的shell并获取它以处理shell语法。

In this case, try something like this: 在这种情况下,请尝试以下操作:

String[] temp = new String[] {
    "cmd", "/c",
    "ffmpeg\\ffmpeg.exe -i input_track.ac3 -threads 0 " + 
    "-af volume=volume=\"0.0\"dB -acodec pcm_s32le -ac 6 " +
    "-ar 48000 -f wav - | " +
    "ffmpeg\\fdkaac --ignorelength -m 1 -o ouput_track.aac -"
};

Note that the actual command is a single string. 请注意,实际命令是单个字符串。 (The quotes around the 0.0 look a bit strange, but that is what you have in your question.) 0.0周围的引号看起来有些奇怪,但这就是您所提出的问题。)

| | is a shell pipe character, in java you'll have to either run this command in a shall (bash -c "the whole commandline | goes here"), or you'll have to run two processes (the one before the | and the one after), where the stdout of the first writes into the stdin of the second. 是一个shell管道字符,在java中,您将必须在一个必运行项中运行此命令(bash -c“整个命令行|在此处”),或者您必须运行两个进程(一个在|和之前后一个),其中第一个的stdout写入第二个的stdin。 For this, you'd typically use redirectOutput(Redirect.PIPE) and redirectInput(Redirect.PIPE) . 为此,通常将使用redirectOutput(Redirect.PIPE)redirectInput(Redirect.PIPE)

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

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