【发布时间】:2020-11-20 20:47:56
【问题描述】:
我有一个 Java 程序,它应该制作视频片段的副本,然后使用 ffmpeg 将它们缝合在一起。我的“snip”方法,即制作分段文件的方法,有一个问题,当我调用“process.waitfor()”时它卡住了。当我拿出它时,视频会部分加载,但在我关闭程序之前无法访问。当我尝试删除它们时,在程序运行时,它说它们无法删除,因为它们正在使用中。谁能带领我朝着正确的方向前进?方法如下:
//snips out all the clips from the main video
public void snip() throws IOException, InterruptedException {
for(int i = 0; i < snippets.size(); i++) {
//Future reference: https://stackoverflow.com/questions/9885643/ffmpeg-executed-from-javas-processbuilder-does-not-return-under-windows-7/9885717#9885717
//Example: ffmpeg -i 20sec.mp4 -ss 0:0:1 -to 0:0:5 -c copy foobar.mp4
String newFile = "foobar" + String.valueOf(i) + ".mp4";
ProcessBuilder processBuilder = new ProcessBuilder("ffmpeg", "-i", videoName, "-ss",
snippets.get(i).getStartTime(), "-to", snippets.get(i).getEndTime(), newFile);
//I tried this first and then added in the process/process.waitfor below
//processBuilder.start();
Process process = processBuilder.start();
process.waitFor();
System.out.println("Snip " + i + "\n");
//add to the formatted list of files to be concat later
if(i == snippets.size() - 1) {
stitchFiles += newFile + "\"";
}
else {
stitchFiles += newFile + "|";
}
}
}
【问题讨论】:
标签: java ffmpeg processbuilder