如何停止通过java进程运行的ffmpeg [英] How to stop ffmpeg that runs through java process

查看:1319
本文介绍了如何停止通过java进程运行的ffmpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中运行ffmpeg。使用 p = Runtime.getRuntime()。exec(command); 它用于通过red5服务器流式传输视频。



我的问题是ffmpeg需要按下q才能停止。我怎样才能做到这一点?如何将q字符发送到正在运行的进程,以便它将执行 p.destroy(); 或类似的东西?目前,它永远运行,直到我在任务管理器中杀死进程。我正在使用Windows7。

解决方案

要将'q'键注入正在运行的过程,可以这样做:

  OutputStream ostream = p.getOutputStream(); //获取进程的输出流,这将转换为命令行
ostream.write(q\\\
.getBytes())的用户输入。 //写出字符Q,后跟换行符或回车符,以便注册Q已经被打字和输入。
ostream.flush(); //写出缓冲区。

应该成功地退出运行的ffmpeg进程。


I am running ffmpeg in Java. Using p = Runtime.getRuntime().exec(command); It is used to stream video through a red5 server.

My problem is that ffmpeg requires "q" to be pressed in order to stop. How can I do that? How can I send the q character to the running process so it will execute p.destroy(); or something similar? At the moment it runs forever until I kill the process in the task manager. I am using Windows7.

解决方案

To inject the 'q' key into the running process, you can do something like this:

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.

This should successfully 'quit' the running ffmpeg process.

这篇关于如何停止通过java进程运行的ffmpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆