1

My objective is to take a twitch video stream and generate an image sequence from it without having to create an intermediary file. I found out that ffmpeg can take a video and turn it into a video and turn it into an image sequence. The ffmpeg website says that it's input option can take network streams, although I really can't find any clear documentation for it. I've searched through Stack Overflow and I haven't found any answers either.

I've tried adding the link to the stream:

ffmpeg -i www.twitch.tv/channelName 

But the program either stated the error "No such file or directory":

"No such file or directory"

or caused a segmentation fault when adding https to the link.

I'm also using streamlink and used that with ffmpeg in a python script to try the streaming url:

import streamlink
import subprocess

streams = streamlink.streams("http://twitch.tv/channelName")
stream = streams["worst"]
fd = stream.open()
url = fd.writer.stream.url
fd.close()
subprocess.run(['/path/to/ffmpeg', '-i', url], shell=True)

But that is producing the same error as the website URL. I'm pretty new to ffmpeg and streamlink so I'm not sure what I'm doing wrong. Is there a way for me to add a twitch stream to the input for ffmpeg?

user2361174
  • 1,872
  • 4
  • 33
  • 51
  • Does the URL directly refer to a video or to a webpage? – Gyan Apr 02 '18 at 05:52
  • The webpage, I thought the two were equivalent to each other but I suppose that's not the case. I don't know how to find the video url in twitch but I'll try to look for it. – user2361174 Apr 02 '18 at 06:23
  • @Mulvya It seems my second method (the script) is using the video URLs as the input but it seems the behavior is still the same. A segmentation fault with https in the url and "No such file or directory" without it. – user2361174 Apr 02 '18 at 09:14

1 Answers1

0

I've figured it out. Ffmpeg won't pull the files that are online for you, you have to pull them yourself, this can be done by using call GET on the stream url which returns a file containing addresses of .ts files, curl can be used to download these files on your drive. Combine this with my image sequencing goal the process looks like this on python:

import streamlink
import subprocess
import requests

if __name__ == "__main__":
    streams = streamlink.streams("http://twitch.tv/twitchplayspokemon")
    stream = streams["worst"]
    fd = stream.open()
    url = fd.writer.stream.url
    fd.close()
    res = requests.get(url)
    tsFiles = list(filter(lambda line: line.startswith('http'), res.text.splitlines()))
    print(tsFiles)
    for i, ts in enumerate(tsFiles):
        vid = 'vid{}.ts'.format(i)
        process = subprocess.run(['curl', ts, '-o', vid])
        process = subprocess.run(['ffmpeg', '-i', vid, '-vf', 'fps=1', 'out{}_%d.png'.format(i)])  

It's not a perfect answer, you still have to create the intermediary video files which I was hoping to avoid. Maybe there's a better and faster answer, but this will suffice.

user2361174
  • 1,872
  • 4
  • 33
  • 51