从Java的processbuilder执行的ffmpeg不会在Windows 7下返回

我试图建立一个调用ffmpeg二进制文件的ProcessBuilder。 我的问题是调用它,它在MacOs,Ubuntu和WindowsXp下完美返回,但在Windows7下,waitFor()永远不会返回。

在Windows 7下有没有类似的经验? 任何帮助,将不胜感激!

我的命令:

ProcessBuilder pb = new ProcessBuilder( ); pb.command( "C:\\Windows\\System32\\cmd.exe", "/c", "c:\\ffmpeg\\bin\\ffmpeg.exe", "-version" ); 

试过这些:

 pb.command( "c:\\ffmpeg\\bin\\ffmpeg.exe", "-version" ); pb.command( "C:\\Windows\\System32\\cmd.exe", "/c", "start c:\\ffmpeg\\bin\\ffmpeg.exe -version" ); 

结果是一样的。 🙁

看起来你的进程在其out和/或错误的流中写入了一些内容。 它们的缓冲区溢出和进程块。 您应该读出并error handling流程以避免这种情况。

有关详细信息,请参阅“ 何时不运行Runtime.exec() ”

如果你使用的是java 7,你可以这样做:

 File encodingFile = new File(outfile + ".encoding"); ProcessBuilder pb = new ProcessBuilder(vars.config.ffmpeg, "-i", file, "-y", "-s", width + "x" + height, "-vcodec", "libvpx", outfile); //or other command.... encodingFile.createNewFile(); pb.redirectErrorStream(true); pb.redirectInput(ProcessBuilder.Redirect.PIPE); //optional, default behavior pb.redirectOutput(encodingFile); Process p = pb.start(); // if you want to wait for the process to finish p.waitFor(); encodingFile.delete();