linuxffmpeg

How to stop ffmpeg remotely?


I'm running ffmpeg on another machine for screen capture. I'd like to be able to stop it recording remotely. FFMPEG requires that q is pressed to stop encoding as it has to do some finalization to finish the file cleanly. I know I could kill it with kill/killall however this can lead to corrupt videos.

Press [q] to stop encoding

I can't find anything on google specifically for this, but some there is suggestion that echoing into /proc//fd/0 will work.

I've tried this but it does not stop ffmpeg. The q is however shown in the terminal in which ffmpeg is running.

echo -n q > /proc/16837/fd/0

So how can I send a character to another existing process in such a way it is as if it were typed locally? Or is there another way of remotely stopping ffmpeg cleanly.


Solution

  • You can simply use killall -INT ffmpeg to send ffmpeg a SIGINT instead of SIGTERM, and they should exit cleanly.

    Edit: Removed mention of q not being available because they have restored it long since.