hack33r.com

Using youtube-dl and ffmpeg to forward streams

Sep
16

youtube-dl is a handy tool for anyone wanting to download or stream videos from youtube and many other sites on the internet. They have pretty decent documentation on how to download videos. You can also use youtube-dl and ffmpeg together to forward video streams and transcode them on the fly. Here is an example of using youtube-dl’s `–exec` option and ffmpeg to stream a video from youtube and forward it to some rtmp location.

youtube-dl -f best \
  https://www.youtube.com/watch?v=gHG9FRSlPxw \
  --exec "ffmpeg -re -i {} -f flv rtmp://localhost:81/test/test";

The previous example works great with youtube but I found issues trying to use youtube-dl’s `–exec` option. Another way of streaming video and audio from youtube-dl to ffmpeg is using a pipe. You can send the contents from youtube-dl to stdout and pipe that to ffmpeg. The following is an example of streaming an mp4 using a pipe.

youtube-dl -f best \
  https://mp4sonly.org/video/foovid.mp4 \
  -o - | ffmpeg -re -f mp4 -i pipe:0 -ar 44100 -f flv rtmp://localhost:1935/test/test'

2 Responses to Using youtube-dl and ffmpeg to forward streams

  1. Awesome. how can I stream HLS tho?

    • In the examples from the post ‘rtmp://localhost:1935/test/test’ is an rtmp media server of some kind (could be FMS, Red5, or nginx with the rtmp module). That server handles the streaming to clients, or if you wanted to ‘forward’ the stream to some streaming service. You’d likely look for some kind of ‘external encoder’ configuration which would contain the rtmp:// url you’d use instead.

Leave a Reply

Your email address will not be published. Required fields are marked *