en
  English
Phone :  +370 (5) 204-1903
Email: sales@1gbits.com

Create your own streaming server with Linux

Nowadays, we access video streaming platforms very frequently. Isn’t it? Platforms like Netflix, Prime Video, Hotstar, and many more. Tons of users consume both recorded and live data displayed there endlessly. 

Linux Tutorial Jan 04, 21 by Nisal N 7 min Read
Create your own streaming server with Linux

These videos reach a huge number of masses. Now, there are other cases where people do not tend to share their videos on such a large scale. Besides, some want more amount of control over their data. One such example is Linux, an open-source software. 

Now, before beginning the process, you must have answers to these questions:

  • What is the number of viewers you are expecting?
  • Quality of stream that you want.
  • Where will you store all the streamed data?
  • Who all can access it?
  • Your system requirements.

Once you are clear of these pointers, you can safely move ahead. We recommend that you carry out proper research about your requirements and needs and then proceed. 

There are many other factors too that you need to consider. 

One of them is to handle live streaming successfully. There are chances that the streaming may interrupt, as there are a lot of factors that may lead to that. For instance, streaming involves encoding, transfer, display, buffer, etc. All these pointers can delay the live streaming or cause hindrance. 

Moving ahead, let us quickly discuss how to install the server.

Linux server setup

We will deal with Ubuntu. Therefore, download the Ubuntu server into your system. After that, start the installer and select the settings as per your requirements. 

When the installation concludes, simply reboot the system if there is no automatic restart of the system. 

Once the system is rebooted, check for updates. If there are any, install them and you are good to go.

sudo apt update

sudo apt upgrade

After you are done with the upgrade of your Ubuntu server (if any) just move on to the next step. The next step is to select a web streaming server. We are taking the Nginx streaming server as this is one of the most powerful and credible options available in the market. 

Follow this below-mentioned command to install Nginx:

sudo apt install nginx

Now, the question is how will the server handle media streams. For that, you have to get the RTMP module. Well, have a look!

sudo add-apt-repository universe

sudo apt install libnginx-mod-rtmp

Now, in order to deliver or accept the media stream, simply set the Nginx’s configuration.

No, it’s not cumbersome, just add this below-mentioned code to the bottom of your config file.

rtmp {
       server {
               listen 1935;
               chunk_size 4096;
               application live {
                       live on;
                       record off;
               }
       }
}

After writing this piece of code, save the particular config file. It shall be used later. 

Now, you have to restart the server prior to your first stream on the platform. Type the below-mentioned command to restart: 

sudo systemctl restart nginx

That’s it. You have successfully set up the server. 

Moving on, after the server is up and running, the next step is to set the streaming software. 

Set the Streaming Software

We will use OBS or Open Broadcaster Software for the process. Start the installation process for OBS. A first-time run wizard appears on the screen. Next, follow the below-mentioned steps. 

  • Start to configure the settings of OBS that match best with the hardware requirements. 

  • Click on +just to add the streaming source as shown below.

  • Now, to carry out the testing, click on Display Capture. Enter source name.
  • Press ok.

Now that the video stream is configured, let us deliver it to the server.

Go to the OBS, click on File and then Settings. You see a Stream section, select that and then process to set the Stream type. Select Custom Streaming server. 

Now, head towards the URL and enter rtmp://IP address of streaming server/ live. The next step is to enter a special identifier that helps you to view the stream, that is, a Stream key. Enter the desired key and then press Apply and click OK.

Everything is set now. You can initiate your first stream. Just choose, Start streaming.

As soon as you choose this, you will see such a box shown below.

Now, be your first visit. As you have RTMP, install one of the most compatible open-source media players, VLC media player, to get things going. Open the VLC and click on Media. Go to Open network stream.  Now, remember you had set a stream key while setting up OBS? Enter that path to the stream and press play. 

Congratulations! Here is your first live stream.

Now, here are some additional tips for your comfort. Have a look.

Additional pointers

Control the access: by default the setup lets any user access or stream from the server. Therefore, you can limit access to the server for better protection and control. There are tons of ways to conclude this task. For instance, a .htaccess file, an OS firewall or several built-in controls in the RTMP module.

Record your media streaming: as you have seen above that, we have set Nginx web server, the configuration of Nginx lets you stream and not save the videos. If you wish to save your media, follow these simple steps.  

  1. Go to Nginx config and head toward the RTMP module. 
  2. Here you have to set the location and recording options as well.
  3. Mention the path where you wish to save the videos carefully.

Take a look at the below-mentioned snippet.

application live {
            live on;
            record all;
            record_path /var/www/html/recordings;
            record_unique on;
}

In a Nutshell

This article provided a step by step guide to set up your own video streaming server with Linux. Do follow the above-stated steps to accomplish the task. We hope that the information helps you in an easy installation.

author img

Nisal N

Computers has always fascinated me since I was a kid and here we are. I love travelling for 2 reasons: the first one to see a new part of the world and second (the most important one) to experience the rich culture hidden among the country and people. I'm pretty good at cooking but very poor when it comes to baking.

Leave A Comment