I am trying to read from a POE streaming camera and write to file. I have it working from the command line with the following command:
ffmpeg -y -i rtsp://admin:admin@192.168.1.200 -acodec copy -vcodec copy out.mp4
When I hit Ctrl+C, it exits with:
Exiting normally, received signal 2.
and I am able to view the saved file.
I need to wrap this in Python. From reading online, it appears that using the subprocess library would be best. This is the bare bones code:
import ffmpeg
from subprocess import Popen
import signal
import time
handle = Popen("ffmpeg -y -i rtsp://admin:ambi1234@192.168.1.200 -acodec copy -vcodec copy out.mp4",shell=True)
time.sleep(5)
handle.kill()
# handle.send_signal(signal.SIGINT) # This doesn't work either
The behavior I see is that after 5s, the script exits, but ffmpeg is still working. No matter how many times I send ctrl+C, it continues. Closing the Terminal stops it, but the file is unplayable.
How do I terminate the process cleanly?