External command not fully executed - Java

So, I am creating a program that converts .flv files to other formats. For this, I use ffmpeg, which does its job fine by executing it through the command line. For instance:

ffmpeg -i C:\test.flv -acodec libmp3lame -y C:\test.mp3

This example works like a charm - there is no problem running the command.

BUT, when I try to execute the same command from a Java class, a problem occurs. I do this in a try-catch block:

System.out.println("Start");
Process p = Runtime.getRuntime().exec("cmd /c ffmpeg -i C:\test.flv -acodec libmp3lame -y C:\test.mp3");
System.out.println("End");

The console prints "Start." It starts to convert, and it does not end.
Can someone help me?

+5
source share
4 answers

, . , . , voila, .

InputStream in = p.getErrorStream();
int c;
while ((c = in.read()) != -1)
{
    System.out.print((char)c);
}
in.close();
+5

:

+3

", - :

cmd "ffmpeg" -i "C:\test.flv" -acodec "libmp3lame" -y "C:\test.mp3"

cmd "ffmpeg -i C:\test.flv -acodec libmp3lame -y C:\test.mp3"
0

, DOS. , Microsoft Windows.

You can do this with help p.waitFor(), as @aioobe explains, or you can use the shell API for FFMPEG like Xuggler , it would be easy to use and it has LGPL.

0
source

All Articles