How to stop ffmpeg that runs through java process

ε祈祈猫儿з 提交于 2019-12-13 01:14:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/17123118/how-to-stop-ffmpeg-that-runs-through-java-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!