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

DopeLabs dopelabs at dubstep.fm
Mon Sep 4 19:41:36 EEST 2017


$ youtube-dl -F https://www.youtube.com/watch?v=mosPaiR-nrs
[youtube] mosPaiR-nrs: Downloading webpage
[youtube] mosPaiR-nrs: Downloading video info webpage
[youtube] mosPaiR-nrs: Extracting video information
WARNING: unable to extract uploader nickname
[youtube] mosPaiR-nrs: Downloading MPD manifest
[info] Available formats for mosPaiR-nrs:
format code  extension  resolution note
139          m4a        audio only DASH audio   51k , m4a_dash container, mp4a.40.5@ 48k (22050Hz), 20.02MiB
249          webm       audio only DASH audio   64k , opus @ 50k, 21.96MiB
250          webm       audio only DASH audio   83k , opus @ 70k, 28.86MiB
140          m4a        audio only DASH audio  131k , m4a_dash container, mp4a.40.2 at 128k (44100Hz), 53.46MiB
171          webm       audio only DASH audio  141k , vorbis at 128k, 52.00MiB
251          webm       audio only DASH audio  160k , opus @160k, 56.51MiB
160          mp4        256x144    DASH video  113k , avc1.4d400c, 25fps, video only, 34.41MiB
278          webm       256x144    144p  170k , webm container, vp9, 25fps, video only, 41.41MiB
242          webm       426x240    240p  350k , vp9, 25fps, video only, 88.67MiB
133          mp4        426x240    DASH video  374k , avc1.4d4015, 25fps, video only, 70.73MiB
243          webm       640x360    360p  655k , vp9, 25fps, video only, 164.62MiB
134          mp4        640x360    DASH video  779k , avc1.4d401e, 25fps, video only, 149.69MiB
244          webm       854x480    480p 1193k , vp9, 25fps, video only, 289.00MiB
135          mp4        854x480    DASH video 1696k , avc1.4d401e, 25fps, video only, 309.33MiB
247          webm       1280x720   720p 2299k , vp9, 25fps, video only, 579.09MiB
136          mp4        1280x720   DASH video 2426k , avc1.4d401f, 25fps, video only, 542.95MiB
137          mp4        1920x1080  DASH video 3961k , avc1.640028, 25fps, video only, 854.86MiB
248          webm       1920x1080  1080p 4034k , vp9, 25fps, video only, 1.04GiB
17           3gp        176x144    small , mp4v.20.3,  mp4a.40.2@ 24k
36           3gp        320x180    small , mp4v.20.3,  mp4a.40.2
43           webm       640x360    medium , vp8.0,  vorbis at 128k
18           mp4        640x360    medium , avc1.42001E,  mp4a.40.2@ 96k
22           mp4        1280x720   hd720 , avc1.64001F,  mp4a.40.2 at 192k (best)


$ youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]' https://www.youtube.com/watch?v=mosPaiR-nrs
[youtube] mosPaiR-nrs: Downloading webpage
[youtube] mosPaiR-nrs: Downloading video info webpage
[youtube] mosPaiR-nrs: Extracting video information
WARNING: unable to extract uploader nickname
[youtube] mosPaiR-nrs: Downloading MPD manifest
[download] Destination: Маша та Ведмідь - На кухні з Машею (всі серії підряд) Masha and the Bear-mosPaiR-nrs.f137.mp4
[download] 100% of 854.86MiB in 00:26
[download] Destination: Маша та Ведмідь - На кухні з Машею (всі серії підряд) Masha and the Bear-mosPaiR-nrs.f140.m4a
[download] 100% of 53.46MiB in 00:02
[ffmpeg] Merging formats into "Маша та Ведмідь - На кухні з Машею (всі серії підряд) Masha and the Bear-mosPaiR-nrs.mp4"
Deleting original file Маша та Ведмідь - На кухні з Машею (всі серії підряд) Masha and the Bear-mosPaiR-nrs.f137.mp4 (pass -k to keep)
Deleting original file Маша та Ведмідь - На кухні з Машею (всі серії підряд) Masha and the Bear-mosPaiR-nrs.f140.m4a (pass -k to keep)

 
$ ffprobe -hide banner Маша\ та\ Ведмідь\ -\ На\ кухні\ з\ Машею\ \(всі\ серії\ підряд\)\ Masha\ and\\ thрії\ підряд\)\ Masha\ and\ the.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Маша та Ведмідь - На кухні з Машею (всі серії підряд) Masha and the Bear-mosPaiR-nrs.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.40.101
  Duration: 00:58:49.50, start: 0.000000, bitrate: 2161 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 2029 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

the only problem is youtube-dl downloads each file sequentially, and for live streaming, thats no good. so we use a specific output template.

from the man pages....

 You can merge the video  and  audio  of  two  formats  into  a  single  file  using  -f <video-for-
       mat>+<audio-format>  (requires ffmpeg or avconv installed), for example -f bestvideo+bestaudio will
       download the best video-only format, the best audio-only format and mux  them  together  with  ffm-
       peg/avconv.

but the most important bit is...

Note that if you use youtube-dl to stream to stdout (and most likely to pipe it
       to your media player then), i.e.  you explicitly specify output template as -o -, youtube-dl  still
       uses -f best format selection in order to start content delivery immediately to your player and not
       to wait until bestvideo and bestaudio are downloaded and muxed.


hope this helps =]

cheers

> On Sep 4, 2017, at 7:38 05AM, Moritz Barsnick <barsnick at gmx.net> wrote:
> 
> 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
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> 
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-user mailing list