Stop an ffmpeg process
See original GitHub issueWould be great to see an implementation of a class method to kill the process gracefully (with ‘q’).
I´m trying to stop the ffmpeg process by killing it with SIGINT. Here is a stripped down code of my threading class:
def is_process_running(self, process_name):
p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
if bytes(process_name, 'utf-8') in line:
pid = line.split()[0]
return pid
return False
def kill_process(self):
logger.info('Stopping FFMPEG')
proc = is_process_running('ffmpeg')
if proc:
os.kill(proc, signal.SIGINT)
Here is the traceback:
Exiting normally, received signal 2.
Exception in thread ffmpeg-thread:
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "observer.py", line 45, in run
self.ff_stream.run()
File "/Users/levy/Code/streampimp/venv/lib/python3.5/site-packages/ffmpy.py", line 104, in run
raise FFRuntimeError(self.cmd, ff_command.returncode, out[0], out[1])
ffmpy.FFRuntimeError: `ffmpeg -re -i [the-input-output-parameters]` exited with status 255
I´m curious to know how you are dealing with stopping ffmpeg. Note that I´m running ffmpeg in a separate thread.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:19 (3 by maintainers)
Top Results From Across the Web
How to stop ffmpeg remotely? - linux - Stack Overflow
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...
Read more >How can I stop FFMPEG? - linux - Server Fault
On Linux, you can use sudo killall ffmpeg to kill every process called "ffmpeg" or ps -ef | grep ffmpeg to get the...
Read more >how to cleanly stop ffmpeg? - LinuxQuestions.org
i'd like to know how to gracefully stop ffmpeg and have it finish as if the feed has ended. i want to play...
Read more >No Way to Cleanly Terminate ffmpeg.exe while capturing screen
You can manually terminate the program with CTRL+BREAK which is better than nothing but if you use the command (in a batch/automated process):...
Read more >How to stop the ffmpeg command · Issue #361 - GitHub
i run that ffmpeg command in separate thread. Now i am able ho cancel the ffmpeg onGoing process. Thanks for your response.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@busla I made this change in version 0.2.2. You can now call
terminate()
onFFmpeg.process
from another thread to terminate the process forcefully.Was able to use the above suggestions to make this work for me:
You need to pass
input_data=subprocess.PIPE
into run() so that you can send the encoded ‘q’ keystroke later on.