Best way to launch FFMpeg process within a python webservice

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.

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.

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.

In my program I can first doing a UDP check once data is received start the process within a task.

def datagram_received(self, data, addr):
        if (self.check_task is not None):

        self.transport.close()"Got UDP Data starting FFMPEG")


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. 

    async def launch(self):
    self.proc = await asyncio.create_subprocess_exec(
    , stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
    )"Run FFmpeg")
    print(f'Process pid is: {}')
    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}')

Read more here: Source link