0

有没有办法知道命令的执行时间?使exec同步

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

ffmpeg 命令需要时间,所以我想在执行后记录一些内容。命令执行后有什么方法可以记录这些东西吗?

4

1 回答 1

1

您可以记录流程开始之前的时间,等待它完成,然后再次记录时间,并将两者相减:

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");
于 2020-11-18T20:30:53.403 回答