我遇到了问题。我想使用 ffmpeg 转换视频,但它没有给我输出
public void convert(String inputFile, String outputFile, String ... optionalParams) {
ProcessBuilder processBuilder = new ProcessBuilder("ffmpeg", "-i", "\"" + inputFile.trim() +"\"", "\""+ outputFile.trim() + "\"");
DownloadRecord downloadRecord = table.getItems().get(0);
downloadRecord.setStatus("Downloading");
// Try to execute process
try {
// Set the working directory
processBuilder.directory(new File(workingDirectory));
//Start the process
Process process = processBuilder.start();
// Read the output from cmd
BufferedReader r = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader ra = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
String errline;
while ((line = r.readLine()) != null) {
System.out.println(line);
}
while ((errline = ra.readLine()) != null) {
System.out.println(errline);
}
process.waitFor();
System.out.println("the end");
} catch(IOException | InterruptedException e) {
System.out.println(e.toString());
}
}
我一直在 stackoverflow 上搜索并找到一些解决方案,但没有任何效果。到目前为止我尝试过并弄清楚的
- 无输出或错误输出
- 我尝试从 ProcessBuilder 中删除反斜杠,它 也没有给我任何输出
- 我试图让程序运行,但它永远不会完成
- 我尝试使用 ffmpeg 的完整路径,没有更改
- 我尝试运行视频,没有错误
- 我正在使用 Netbeans IDE 所以我尝试清理并重建项目,没有改变
- 进程也永远不会结束
我想从中得到一个输出。有人知道我在这里做错了什么吗?
最佳答案
我通过重新安装 ffmpeg 修复了这个问题。刚刚去 ffmpeg 网站下载了最新版本,替换了文件夹中的文件,它就可以工作了
编辑: 由于某种原因,它仅适用于少于 2 分钟的文件,超过 2 分钟的文件的行为如下 我开始转换,直到程序运行它才会完全转换。当我退出程序后,它就会完成。这是奇怪的行为。
关于Java FFmpeg 无输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53989179/