我正在 Java 中运行 ffmpeg。使用p = Runtime.getRuntime().exec(command);
它用于通过 red5 服务器传输视频。
我的问题是 ffmpeg 需要按下“q”才能停止。我怎样才能做到这一点?如何将 q 字符发送到正在运行的进程,以便它执行 p.destroy();
或者类似的东西?目前它会永远运行,直到我在任务管理器中终止该进程。我使用的是Windows7。
最佳答案
要将“q”键注入(inject)正在运行的进程中,您可以执行以下操作:
OutputStream ostream = p.getOutputStream(); //Get the output stream of the process, which translates to what would be user input for the commandline
ostream.write("q\n".getBytes()); //write out the character Q, followed by a newline or carriage return so it registers that Q has been 'typed' and 'entered'.
ostream.flush(); //Write out the buffer.
这应该成功“退出”正在运行的 ffmpeg 进程。
关于java - 如何停止通过java进程运行的ffmpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17123118/