Create your own streaming server (advanced)
Today, we are going to create our own streaming server. What is a streaming server? It is simply a computer that will distribute broadcasts to our viewers. This means that we don’t need a platform like YouTube or Facebook – we will host the stream ourselves. Once we have setup the server, we will use StreamYard to send it a broadcast. People can then watch the stream in a video player, like VLC, or play it in an embedded video player on our own website. The basic flow of what were doing looks like this:
We will create the server on Google Cloud. I have found Google Cloud extremely easy to use and it will allow us to work through the tutorial without leaving our browser. They also offer a $300 credit!
The software our server will run is called Nginx. We will use the RTMP module and this image to download it easily.
Let’s get started.
After you create your Google Cloud account here, navigate to the console.
Create a new project and name it whatever you want. I named mine demo
and
my project ID is rosy-cooler-211104
. If you have never done this before,
Google might take you through a wizard.
Select your new project and go to the compute instances section.
Google might need some time to load this service. I found that it will occasionally hang – try refreshing the page if it has been over a minute or two. After Google is ready, click the create button.
You will see a menu with many options. Most of the defaults are fine, but there are two things that we should change.
- Change the Machine type to micro. You can choose a larger machine type if you plan on having many viewers.
- Check the “Deploy a container image to this VM instance” and in the “Container image” field put tiangolo/nginx-rtmp
Scroll down and click create. After a few seconds you should see something like this:
Click the SSH button to connect to the server.
After it finishes loading you should be in a terminal window. Type docker ps
to check if your server is running. If
you see something similar to the following output, you’re in good shape.
Now we need to open up the firewall so that we can communicate to the server from StreamYard. Go back to the page where you connected to the server using SSH. Click on the settings for your instance (3 dots) and click “view network details”.
On left of the page there are several options. Select firewall rules and click “Create Firewall Rule”.
For the source IP ranges put 0.0.0.0/0 and for Protocols and ports enter tcp:1935
. Name your rule and select all
instances in the network as your target. Hit Create.
Our server should be set up now! Navigate back to the compute section and take note of your ip address.
The RTMP server URL is rtmp://YOUR_IP_ADDRESS/live
The key can be whatever you like. I am using test
.
Go to your StreamYard dashboard and add an RTMP server. Enter your server URL and stream key. Create a broadcast and go live.
You should be able to see your stream on VLC player. If you just want to use your browser, you should be able to watch the stream on this website.
If you’d like to watch the stream on your own wordpress website, try using this plugin.
That’s it! If you no longer need the server simply delete the project or navigate to the compute instances section and delete the server.