A few days ago, we opened the sources of one of our in-house projects — Yourcast TV.

The history behind it

It was a warm and sunny day in October of 2016. I was at my work, drinking some coffee and solving some tasks. Everything was fine, and there were no signs of trouble. Then Oleg Puzanov came into the building. "Look," he said, "I need a script or service or whatever. I need any solution that helps me to create a stream from YouTube links. Online stream". "Why?" — I asked. "Because I want to watch live streams of videos from past conferences," he answered. "Ok," I said, "Give me a few days to think and do some research."

I took a few days to think and make some tries.

First steps

First, we need to know how to download an MP4 file from YouTube. In this case, the YouTube-dl project helps us. I didn't want to do any additional work and tried to make my solution very simple and very stupid.

I took YouTube-dl and got a download link of an MP4 video in a few minutes.

But there is the main challenge here — HTTP streaming.

I had options:

  1. MP4 HTTP streaming via VLC
  2. Same, but with FFmpeg
  3. Use the Nginx RTMP module

OK. I took Flash FlowPlayer and started to dig again.

I achieved a working prototype with Flash, VLC, and HTTP streaming, and we started to think about how to make a service with it.

Making service. Building architecture

The conclusion after we had a working prototype was — OK, let's make a service from your prototype.

We need an admin interface to manage streams, and we need a streamer component to run streams and make them available. We chose the Django framework for it, and the plan was:

  1. Use the standard Django admin interface
  2. Make an HTTP API for the streamer component
  3. Get streams from Django and run them on the streamer component

As for Django, it was a very simple realization of it using signals, simple models, and serialization.

Image.

The streamer

As for streamer, we chose Go, and we need an alternative to YouTube-dl for the Go programming language. After some research, we chose this library. It has a clear API, and we have no problems using it.

The streamer component should have an infinite loop, and in that loop, we need to get the download URL for a YouTube video in a proper format and then run the stream. We decided to move to nginx-rtmp-module for the task because we had some experience in the past with it.

The final algorithm was like this:

  1. Get all streams via HTTP API from the Django app.
  2. Run a goroutine per stream with a waitgroup for sync.
  3. Ge the download URL from YouTube.
  4. Spawn FFmpeg process to stream video to nginx-rtmp-module.

HTML5

In some first versions playing of live streams was implemented using Flash and RTMP. But it doesn't work for mobile devices, and we decided to find a way to move to HTML5.

After some tries, we found that nginx-rtmp-module with videojs and hls.js works fine for us.

Testing and using

We started to test our implementation with streaming videos from past conferences like DockerCon 2016, GopherCon, and others. We used one of our big monitors on the wall to play videos, test it for bugs, and educate in the background.

Is it an open source? Where can I find the code?

Yes. We opened source several days ago, and you can find it on our GitHub.

What problems we faced and how we solved them, read in our article "How We Set Up Google Analytics for Live Streaming App".

Issues, feature requests, contributing, and any other requests are welcome.

Try to be a producer of your own TV stream for free, without registration and SMS :)

Custom software solutions by Mad Devs.

Latest articles here

How to Run Code Climate Code Analysis Locally Using VSCode + Remote-Containers.

How to Run Code Climate Code Analysis Locally Using VSCode + Remote-Containers

Everyone who writes code knows that the best code is code that is not written! But as they say, everyone is not perfect, and we have to write code....

Amazon Aurora vs AWS RDS

AWS Aurora vs AWS RDS

In the realm of cloud-based database solutions, Amazon Web Services (AWS) offers an impressive array of options to cater to various business needs....

Stripe Connect.

Integration of Stripe Connect Into Your Project

Almost every service on the Internet today deals with money. And dealing with money requires a robust Billing system. Building your own billing...

Go to blog