Youtube Stream to TD

Hi All,

I’ve been trying for a few days now to get a youtube stream into TD. I’m aware of the YoutubeTOP project (github.com/remap/YoutubeTOP) that Peter Gusev made but unfortunately it is only compiled for 32bit TD and seems to be made for videos rather than streams.

I thought I might be able to use youtube-dl to pipe video into ffmpeg and transcode it to a rtsp/rtmp stream which TouchDesigner could then receive via the VideoStreamIn TOP. The command would look something like this:

youtube-dl -f best "https://youtu.be/RtU_mdL2vBM" -o - | ffmpeg -re -f mp4 -i pipe:0 -ar 44100 -f flv rtmp://localhost:1935/test/test'

To view:

vlc rtmp://localhost:1935/test/test

This could also be done with vlc:

vlc -vvv https://youtu.be/RtU_mdL2vBM --sout '#transcode{vcodec=h264,vb=800,acodec=none}:rtp{sdp=rtsp://:554/test}'
or

youtube-dl -o - "https://youtu.be/RtU_mdL2vBM" | vlc - --sout '#transcode{vcodec=h264,vb=800,acodec=none}:rtp{sdp=rtsp://:554/test}'
and to view:

vlc rtsp://localhost:554/test

So far I haven’t been able to connect to the transcoded stream with TouchDesigner or VLC although I can play the youtube stream directly with either of these commands:

youtube-dl -o - "https://youtu.be/RtU_mdL2vBM" | vlc -

vlc -vvv https://youtu.be/RtU_mdL2vBM

I’ve also tried to use ffserver running on a ubuntu 16.04 machine between ffmpeg and TouchDesigner/VLC but haven’t had any success.

I’ve made a post on stackoverflow that contains a bit more information including the ffmpeg log. I’m curious if anyone has done this in the past or knows what I’m doing wrong. It would be really cool to have this working!

[url]Using youtube-dl and ffmpeg (or vlc) to transcode a YouTube live stream to rtsp rtmp udp rtp - Stack Overflow

Thanks!

EDIT:
This is solved in the post below but I’ve been experimenting with other command line tools and found one that works particularly well called livestreamer [url]http://docs.livestreamer.io/[/url]
[url]http://docs.livestreamer.io/plugin_matrix.html[/url]

This has proven to be a bit more reliable than youtube-dl or vlc and has a nice option to retry the stream if it is lost.

livestreamer --retry-streams 1 https://www.youtube.com/watch?v=UQt2iLKqBbI best -O | vlc - --sout=#transcode{vcodec=h264,vb=15000,acodec=none}:rtp{sdp=rtsp://:563/test,proto=udp}

One thing you will need to do is edit the youtube plugin file. For some reason it is broken in the official release.

C:\Users[username]\AppData\Local\Programs\Python\Python35\Lib\site-packages\livestreamer\plugins\youtube.py

under _get_stream_info comment out “el”: “player_embedded” in the “params” dictionary like so:

        params = {
            "video_id": video_id,
            #"el": "player_embedded"
        }

Enjoy!

1 Like

Well, the solution ended up being pretty simple. Here’s the correct way to write the command (I was missing a ‘=’ after the --sout option and didn’t need the quotes around the parameters; this is different in linux):

youtube-dl -o - "https://www.youtube.com/watch?v=UQt2iLKqBbI" | vlc - --sout=#transcode{vcodec=h264,vb=800,acodec=none}:rtp{sdp=rtsp://:554/test}

Strange thing is that I still haven’t been able to get ffmpeg to do the transcode. Maybe I have some incorrect options there?

also if I try to get the stream with vlc using the command below, I only get a small corner of the image in TouchDesigner.

vlc -vvv https://youtu.be/RtU_mdL2vBM --sout=#transcode{vcodec=h264}:rtp{sdp=rtsp://:554/test}

I’m curious if anyone has a solution for ffmpeg or the vlc only method.

Thanks!

So would a Youtube stream by this method have any benefits over using a webRender Comp from the palette?

Using this format you can get videos to start in YT full window mode
youtube.com/embed/tussa6KKCZU

Might not be what you are looking for, but is a very simple way of getting YT into TD

Yep, I tried that first but the youtube video window shows an error:

Ok Roger that. It depends on the format of the YT video, some videos do indeed work with the Chromium, some do not.

Hi I’m a beginner of TD
I have tried the method with livestreamer.
but when I type :
livestreamer --retry-streams 1 https://www.youtube.com/watch?v=INR-B7FwhS8 | vlc - --sout=#transcode{vcodec=h264,vb=15000,acodec=none}:rtp{sdp=rtsp://:563/test,proto=udp}
I always get this, do you know what’s wrong with my command?

thank you

I have successfully input the youtube live video into TD, but it is very unstable. It can only maintain about 2 minute, then turn into a black image with a little rectangle at the corner.

I just can’t figure out what the problem is.
is it about the internet speed?
Do you have any idea about this?

Thank you

Yeah I’ve had some trouble getting the streams to be stable as well. Seems like this has become worse somehow. Not really sure what could have changed other than something on youtube’s end. Usually I could get streams to run for a few hours before they would randomly stop.

Now that the Video Stream In TOP supports HLS/DASH I wonder if it would be worth just trying to manage the m38u playlist yourself. The answer on this post gives a little info on how you might do that: How can I get the actual video URL of a YouTube live stream? - Stack Overflow