title: Best way to launch FFMpeg process within a python webservice
body: <p>I am building a local proxy tool for HLS playback. And I am having trouble finding a way to efficiently run an ffmpeg pipeline within the python webservice. Which is to run a websocket and serve static files.</p>
  <p>I am hoping my choices of software are ok as it needs to be as light as possible. I am using asyncio based functions within starlette and launched by uvicorn on Windows.</p>
  <p>I have launched the process via a task. But Ffmpeg seems to be constantly being stalled so not writing HLS fragments to disk fast enough. On the command line its fine.</p>
  <p>In my program I can first doing a UDP check once data is received start the process within a task.</p>
  <pre><code>def datagram_received(self, data, addr):
          if (self.check_task is not None):
              self.check_task.cancel();
  
          self.transport.close()
  
          logging.info(&quot;Got UDP Data starting FFMPEG&quot;)
  
          asyncio.create_task(send_info_to_client(self.websocket))
          asyncio.create_task(startFFMpegProcess(self.launcher))
      ```
  
  Then something like this. Do I need to use Popen and launch in a Daemon thread instead ? Or can this method be launched in a thread ? asyncio.create_subprocess_exec. It seems to stall while serving files but not even when serving files and using an external server. 
  
  </code></pre>
  <pre><code>    async def launch(self):
      self.proc = await asyncio.create_subprocess_exec(
      'ffmpeg/bin/ffmpeg',
      ...
      , stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
      )
  
      logging.info(&quot;Run FFmpeg&quot;)
      print(f'Process pid is: {self.proc.pid}')
      stdout_task = asyncio.create_task(write_output('ffmpeg: ', self.proc.stdout, self.proc.stderr))
      return_code, _ = await asyncio.gather(self.proc.wait(), stdout_task)
      print(f'Process returned: {return_code}')
  </code></pre>
  <pre><code></code></pre>