How to stop ffmpeg remotely?

30,579

Solution 1

Newer versions of ffmpeg don't use 'q' anymore, at least on Ubuntu Oneiric, instead they say to press Ctrl+C to stop them. So with a newer version you can simply use 'killall -INT' to send them SIGINT instead of SIGTERM, and they should exit cleanly.

Solution 2

Here's a neat trick I discovered when I was faced with this problem: Make an empty file (it doesn't have to be a named pipe or anything), then write 'q' to it when it's time to stop recording.

  1. $ touch stop
  2. $ <./stop ffmpeg -i ... output.ext >/dev/null 2>>Capture.log &
  3. $ wait for stopping time
  4. $ echo 'q' > stop

FFmpeg stops as though it got 'q' from the terminal STDIN.

Solution 3

Elaborating on the answer from sashoalm, i have tested both scenarios, and here are the results:

My experiments shows that doing

killall --user $USER  --ignore-case  --signal INT  ffmpeg

Produces the following on the console where ffmpeg was running

Exiting normally, received signal 2.

While doing

killall --user $USER --ignore-case --signal SIGTERM  ffmpeg

Produces

Exiting normally, received signal 15.

So it looks that ffmpeg is fine with both signals.

System: Debian GNU/Linux 9 (stretch), 2020-02-28

Share:
30,579

Related videos on Youtube

Adam
Author by

Adam

Professional Java programmer and father of three. Interested in web technologies, software design, Android dev, lego, animation, ruby etc.

Updated on February 29, 2020

Comments

  • Adam
    Adam over 4 years

    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.

    • sashoalm
      sashoalm over 12 years
      Newer versions of ffmpeg don't use 'q' anymore, at least on Ubuntu Oneiric, instead they say to press Ctrl+C to stop them. So with a newer version you can simply use 'killall -INT' to send them SIGINT instead of SIGTERM, and they should exit cleanly.
    • Multimedia Mike
      Multimedia Mike over 12 years
      @satuon: That version of Ubuntu is likely using avconv (part of the forked Libav project). That utility has removed 'q' as an option; main FFmpeg still has it.