Command execution time in Java

85 Views Asked by At

Is there any way to know the execution time of the command? Making exec synchronous

Runtime rt = Runtime.getRuntime();
Process process = rt.exec(ffmpeg +" -i "+source+" -vcodec h264 -acodec aac  "+destination);

the ffmpeg command is taking time so I want to log something after the execution. Is there any way to log the things after the command has executed?

1

There are 1 best solutions below

5
On

You could record the time before the process starts, waitFor it to finish, and then record the time again, and subtract the two:

long before = System.currentTimeMillis();
Runtime rt = Runtime.getRuntime();
Process process =
    rt.exec(ffmpeg + " -i " + source + " -vcodec h264 -acodec aac  " + destination);
process.waitFor();
long after = System.currentTimeMillis();
long execTime = after - before;
System.out.println("Processing took " + execTime + " milliseconds");