title: Terminating FFMPEG from Python using Linux
body: <p>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:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>to merge the audio and video files I just created.</p>
  
  <p>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?</p>
  
  <p>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.</p>