[FFmpeg-user] How to livestream from youtube video link

Moritz Barsnick barsnick at gmx.net
Mon Sep 4 17:38:05 EEST 2017


On Wed, Aug 23, 2017 at 21:16:57 -0700, johnsmithbin wrote:
> Hello.
> I want livestream from youtube video link. I tried using /youtube-dl
> https://www.youtube.com/watch?v=mosPaiR-nrs -g/ but the link returned is not
> a direct link. How can you help me?

The general issue is that some YouTube formats come as two separate
streams. You can check what youtube-dl can discover by calling
$ youtube-dl -F https://www.youtube.com/watch?v=mosPaiR-nrs

I think the issue with youtube-dl is it claims the composite MP4 format
is "best":
> [...]
> 22           mp4        1280x720   hd720 , avc1.64001F, mp4a.40.2 at 192k (best)

but when using "-g", it doesn't deliver that best format, but two other
URLs for a separate video and audio stream each. Note that, for this
particular clip, there's no composite video+audio format available from
YouTube with the highest resolution of 1920x1080.

You could do
$ ffmpeg -i $(youtube-dl -f "bestvideo" -g https://www.youtube.com/watch?v=mosPaiR-nrs) -i $(youtube-dl -f "bestaudio" -g https://www.youtube.com/watch?v=mosPaiR-nrs) -map 0:v -map 1:a [...]

I believe I have done that and it worked. You may want to query those
URLs first, put them in variables, and then hand these variables to ffmpeg.

Note that, depending on what codecs your livestream requires, you might
need to reencode, as YouTube likes delivering VP9 video and Opus audio,
which may or may not suit your needs. Otherwise, use
"bestvideo[ext=mp4]" and "bestaudio[ext=m4a]", if you prefer H.264 and
AAC.

Good luck,
Moritz


More information about the ffmpeg-user mailing list