1

I am currently trying to save the video of a live stream on the disk using the link to the m3u8 file, passing it to streamlink and then converting everything to ffmpeg, but when the streamer disconnects or the connection drops I get this error

HTTP error 403 Forbidden
Failed to reload playlist 0

and the program never ends, never reach the command line to convert the mkv video in mp4. How can I catch the exception and ignore it?

This is my code

url = 'url.m3u8'

stream_url = streamlink.streams(url)['worst'].url
ffmpeg_process = Popen(["path-to-ffmpeg.exe", "-i",
         stream_url, "-c", "copy", 'file.mkv'])

#to keep main.py alive
while True:
    #check if process ffmpeg still alive, if not break

#never reched
cmds = ['path-to-ffmpeg',
        '-i', 'file.mkv', 'file.mp4']
subprocess.Popen(cmds).wait()
4

0 回答 0