0

This is the whole code, for easy reference:

import urllib.request
import streamlink
import ffmpeg
stream_url = streamlink.streams("https://www.twitch.tv/videos/783301562")['best'].url
print(stream_url)

try:
    urllib.request.urlretrieve(stream_url, "vod.m3u8")
except Exception as e:
    print(e)

stream = (
    ffmpeg
    .input('vod.m3u8')
    .output('output.mp4')
    .run
)
print(stream)

I am looking at a way of downloading Twitch VODs. I started with the link to a VOD: https://www.twitch.tv/videos/783301562 . I then used the code:

stream_url = streamlink.streams("https://www.twitch.tv/videos/783301562")['best'].url
print(stream_url)

This gave me a new link which, when I go to this link it downloaded a file with a '.m3u8' extension. This link is: https://dqrpb9wgowsf5.cloudfront.net/ab3654a5992fbfa52ccb_briziana_40240109614_1603789265/chunked/index-dvr.m3u8

From here, I first tried to put the link directly into the following code:

stream = (
    ffmpeg
    .input(stream_url)
    .output('output.mp4')
    .run
)
print(stream)

This didn't output any mp4 file but did give the output:

<bound method run of output(filename='output.mp4')[None] <2606681a>>

I then added the following code to download the file, I also change the ffmpeg code to use the downloaded file rather then the url:

try:
    urllib.request.urlretrieve(stream_url, "vod.m3u8")
except Exception as e:
    print(e)

stream = (
    ffmpeg
    .input('vod.m3u8')
    .output('output.mp4')
    .run
)
print(stream)

This gave the same result, no mp4 file with the same output as above. Any help would be greatly appreciated!

Daniel Norfolk
  • 13
  • 1
  • 10
  • 1
    It seems that you're not calling the `run` method, try `.run()` instead. As an aside, using `except Exception` like this is bad practice, see https://stackoverflow.com/q/54948548. – AMC Oct 28 '20 at 22:52
  • Thank you for the advice on the bad pactice, I am always looking to making my coding skills better. I changed it to .run() and I am now getting 'FileNotFoundError' for both ways, using the url and downloading the .m3u8 file. I have double checked the name and it definitely correct. – Daniel Norfolk Oct 28 '20 at 23:18
  • I have tried to use both a relative and absolute file path for the file and I keep getting the same error. – Daniel Norfolk Oct 28 '20 at 23:37
  • That's a different issue, it's probably best to create a new question if you can't resolve the problem. – AMC Oct 29 '20 at 00:00
  • The issue is due to some conflict with with PyCharm, I will just have to code using atom or something similar – Daniel Norfolk Oct 29 '20 at 00:43
  • Have you posted a new question? Where is the error occurring? – AMC Oct 29 '20 at 00:45
  • I never posted a new question, I looked at the issues section on the ffmpeg-python github repository and it is a known error. but i am still not sure why the error occurs – Daniel Norfolk Oct 29 '20 at 11:52

0 Answers0