我正在尝试制作一个 java 函数,它在输入中给出一个视频,它会按秒生成一组图像,到目前为止,这就是我所得到的:
public static void decodeAndCaptureFrames(String inputfilename, String outputfolder, int width, int height, double seconds) throws InputFormatException, EncoderException { double duration = getVideoLenght(inputfilename); 整数索引 = 0;
Runtime runtime = Runtime.getRuntime();
for(double s = 0; s < duration; s+= seconds)
{
String outString = outputfolder + File.separator + index + ".png";
String cmd = "ffmpeg.exe -i "+ inputfilename +" -f image2 -t 0.001 -ss "+ s +" -s "+ width +"x"+ height +" "+outString;
try {
Process p = runtime.exec(cmd);
p.waitFor()
} catch (IOException e) {
System.out.println("problema nell'esecuzione del runtime.exec");
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(cmd);
index++;
}
}
然而,代码真的很慢,即使我得到更多图像的打印,它也只会转换前两个图像。由于我使用的是这个外部 exe,有人可以告诉我运行时和进程是否有问题吗?谢谢。