0

i try to run ffmpeg out 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 "|" at the ffmpeg command line.

maybe someone say my fould?

best regards

Pa Rö
  • 449
  • 1
  • 6
  • 18

2 Answers2

1

This question is similar to How to make pipes work with Runtime.exec()? ... except that it is for 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. The solution is essentially the same too: exec the appropriate shell and get that to handle the shell syntax.

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.)

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
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. For this, you'd typically use redirectOutput(Redirect.PIPE) and redirectInput(Redirect.PIPE).

Ronald S. Bultje
  • 10,828
  • 26
  • 47