Ruben
Ruben

Reputation: 21

How to stop ffmpeg that runs through java process

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.

Upvotes: 2

Views: 3782

Answers (2)

Archimedes Trajano
Archimedes Trajano

Reputation: 41300

You may be able to avoid this by passing -nostdin as one of the parameters for FFMpeg. This disables user input.

Upvotes: 0

Corey Ringer
Corey Ringer

Reputation: 43

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.

Upvotes: 2

Related Questions