从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();
- StAX – 从xml读取base64字符串到db
- sessionfactory.openSession()和sessionfactory.openStatelessSession()之间的区别?
- Hibernatevalidation失败时出现意外的UnsupportedOperationException
- 仅列出s3存储桶中的子文件夹
- 阅读mime multipart的身体部分
- 使用executeUpdate()而不是executeQuery()进行SELECT查询
- 嵌套JSON的POJO格式?
- 如何将application.properties中的值赋给静态变量?
- 无法使用Java Desktop在网络上启动文件?