简体   繁体   中英

Terminating FFMPEG from Python using Linux

So I have a project that listens for button inputs in Python, and records video from a camera and an external microphone once a certain button is pressed, now when I want to stop recording, I press another button and stop recording on my camera and the microphone, and then I call ffmpeg using the subprocess module:

mergeFiles = subprocess.Popen("sudo ffmpeg -i /home/pi/Video/video.mov -i /home/pi/Audio/test.wav -acodec copy -vcodec copy -map 0:v -map 1:a -shortest /media/pi/USB/Output/output.mkv", shell=True)

to merge the audio and video files I just created.

Now once I call ffmpeg, it doesn't stop until I send the process a signal interrupt from the keyboard... is there a way to either have the process stop as soon as it's done merging, or to automatically terminate/kill ffmpeg after a certain amount of time?

I have read up on other posts like this and none of the solutions work for me. I can't kill the process using the PID because every time I look up ffmpeg's PID, it is a different ID, and calling something like mergeFiles.kill() doesn't work for me.

I think the reason it is doing this is because the ffmpeg command starts a second process and you don't have the Pid of the second process (just a guess I am not an expert).

My Solution was to call pkill ffmpeg as a subprocess when I want to terminate ffmpeg. ( https://en.wikipedia.org/wiki/Pkill ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM