Reputation: 1015
I am doing as below on centos machine
String fileName = "ffmpeg -i file:///home/xyz %d.png";
Runtime.getRuntime().exec(fileName);
xyz is mp4 file and i want that to create number of different Image frames
when i am running by java application as above it is not working however if i try to do so directly on terminal it is working, please suggest as what might be wrong ?
Upvotes: 1
Views: 1512
Reputation: 21
Apologies if this comes so late, hope it can be useful for somebody. As @rodion was foreseeing, this is definitely related to ffmpeg specific output.
I had a run with -nostats -loglevel 0
options, and then ffmpeg was correctly executed by Runtime.getRuntime().exec("");
Upvotes: 2
Reputation: 15029
The problem may be that the program is outputting a lot to standard out or error. If you do not consume this output, the Java program may hang. Use Process
#getErrorStream()
and getOutputStream()
, in a fashion like this:
is = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ((line = is.readLine()) != null)
System.out.println(line);
This will also help you analyze any error output from the command you run. You may need to do this for both streams.
Additionally, you may need to wait for the subprocess to terminate, using Process#waitFor
, because otherwise your Java program might be finishing execution even though the spawned subprocess is still running in the background (unless this is what you want).
Upvotes: 1