Note that each call to Runtime.exec will spawn a new process that runs in parallel. Are you sure you want to create processes as fast as the loop can go? You probably want int exitValue = p.waitFor() wait for the process to complete. If you need concurrency, I would recommend scheduling tasks using java.util.concurrent.ThreadPoolExecutor .
For example, without much error checking, something like this:
final ExecutorService executor = Executors.newFixedThreadPool(2); for (int j = 0; j < temp.length; j++) { if(j==2) { final String preview = temp2[i] + temp[j] +".jpg"; final String ffmpegPreviewCommand = "ffmpeg -i anotados/" +temp2[i] + " -r 1 -ss 00:00:"+temp[j]+" -t 1 -s 158x116 imagenes/" + preview; executor.submit(new Callable() { @Override public Object call() throws Exception { final Process p = Runtime.getRuntime().exec(ffmpegPreviewCommand); final int exitValue = p.waitFor();
}
Take a look at java.util.concurrent.Executors to choose an artist that suits your needs.
source share