Difference between revisions of "Nginx: Basic Live Video Streaming Server"

From OnnoWiki
Jump to navigation Jump to search
(Created page with "Sumber: https://opensource.com/article/19/1/basic-live-video-streaming-server hot keys for shortcuts or features on computer keyboard Image by : Opensource.com x Subscribe...")
 
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
Sumber: https://opensource.com/article/19/1/basic-live-video-streaming-server
 
Sumber: https://opensource.com/article/19/1/basic-live-video-streaming-server
  
 +
Yang perlu di pikirkan dalam instalasi live streaming video server
  
hot keys for shortcuts or features on computer keyboard
+
* Stream quality: mau HD atau SD?
Image by :  
+
* Viewership: jumlah pemirsa?
Opensource.com
+
* Storage: mau di rekam atau tidak?
x
+
* Access: apakah private atau open?
Subscribe now
 
  
Get the highlights in your inbox every week.
+
Spec Minimal Server:
 +
* 4GB RAM
 +
* 20G harddisk
 +
* 1 core i7
  
Live video streaming is incredibly popular—and it's still growing. Platforms like Amazon's Twitch and Google's YouTube boast millions of users that stream and consume countless hours of live and recorded media. These services are often free to use but require you to have an account and generally hold your content behind advertisements. Some people don't need their videos to be available to the masses or just want more control over their content. Thankfully, with the power of open source software, anyone can set up a live streaming server.
+
Disini digunakan Real-Time Messaging Protocol (RTMP) untuk menangani audio + video streaming. Alternatif lain adalah WebRTC.
Getting started
 
  
In this tutorial, I'll explain how to set up a basic live streaming server with a Linux or BSD operating system.
+
==Setting Server==
  
This leads to the inevitable question of system requirements. These can vary, as there are a lot of variables involved with live streaming, such as:
+
Instalasi nginx
 
 
    Stream quality: Do you want to stream in high definition or will standard definition fit your needs?
 
    Viewership: How many viewers are you expecting for your videos?
 
    Storage: Do you plan on keeping saved copies of your video stream?
 
    Access: Will your stream be private or open to the world?
 
 
 
More Linux resources
 
 
 
    Linux commands cheat sheet
 
    Advanced Linux commands cheat sheet
 
    Free online course: RHEL Technical Overview
 
    Linux networking cheat sheet
 
    SELinux cheat sheet
 
    Linux common commands cheat sheet
 
    What are Linux containers?
 
    Our latest Linux articles
 
 
 
There are no set rules when it comes to system requirements, so I recommend you experiment and find what works best for your needs. I installed my server on a virtual machine with 4GB RAM, a 20GB hard drive, and a single Intel i7 processor core.
 
 
 
This project uses the Real-Time Messaging Protocol (RTMP) to handle audio and video streaming. There are other protocols available, but I chose RTMP because it has broad support. As open standards like WebRTC become more compatible, I would recommend that route.
 
 
 
It's also very important to know that "live" doesn't always mean instant. A video stream must be encoded, transferred, buffered, and displayed, which often adds delays. The delay can be shortened or lengthened depending on the type of stream you're creating and its attributes.
 
 
 
==Setting up a Linux server==
 
 
 
You can use many different distributions of Linux, but I prefer Ubuntu, so I downloaded the Ubuntu Server edition for my operating system. If you prefer your server to have a graphical user interface (GUI), feel free to use Ubuntu Desktop or one of its many flavors. Then, I fired up the Ubuntu installer on my computer or virtual machine and chose the settings that best matched my environment. Below are the steps I took.
 
 
 
Note: Because this is a server, you'll probably want to set some static network settings.
 
 
 
stream-server_profilesetup.png
 
Ubuntu profile setup
 
 
 
After the installer finishes and your system reboots, you'll be greeted with a lovely new Ubuntu system. As with any newly installed operating system, install any updates that are available:
 
  
 
  sudo apt update
 
  sudo apt update
  sudo apt upgrade
+
  sudo apt upgrade (optional)
 +
sudo apt -y install nginx
  
This streaming server will use the very powerful and versatile Nginx web server, so you'll need to install it:
+
Instalasi RTMP agar nginx dapat menangani media stream:
 
 
sudo apt install nginx
 
 
 
Then you'll need to get the RTMP module so Nginx can handle your media stream:
 
  
 
  sudo add-apt-repository universe
 
  sudo add-apt-repository universe
 
  sudo apt install libnginx-mod-rtmp
 
  sudo apt install libnginx-mod-rtmp
  
Adjust your web server's configuration so it can accept and deliver your media stream.
+
Tambahkan konfigurasi di nginx untuk menangani RTMP,
  
  sudo nano /etc/nginx/nginx.conf
+
  sudo vi /etc/nginx/nginx.conf
  
Scroll to the bottom of the configuration file and add the following code:
+
Tambahkan di paling bawah,
  
 
  rtmp {
 
  rtmp {
Line 80: Line 46:
 
  }
 
  }
  
stream-server_config.png
+
Di save konfigurasi-nya.
Nginx configuration
 
 
 
Save the config. Because I'm a heretic, I use Nano for editing configuration files. In Nano, you can save your config by pressing Ctrl+X, Y, and then Enter.
 
 
 
This is a very minimal config that will create a working streaming server. You'll add to this config later, but this is a great starting point.
 
  
However, before you can begin your first stream, you'll need to restart Nginx with its new configuration:
+
Restart nginx
  
 
  sudo systemctl restart nginx
 
  sudo systemctl restart nginx
 +
/etc/init.d/nginx restart
  
==Setting up a BSD server==
 
 
If you're of the "beastie" persuasion, getting a streaming server up and running is also devilishly easy.
 
  
Head on over to the FreeBSD website and download the latest release. Fire up the FreeBSD installer on your computer or virtual machine and go through the initial steps and choose settings that best match your environment. Since this is a server, you'll likely want to set some static network settings.
 
  
After the installer finishes and your system reboots, you should have a shiny new FreeBSD system. Like any other freshly installed system, you'll likely want to get everything updated (from this step forward, make sure you're logged in as root):
 
  
pkg update
 
pkg upgrade
 
  
I install Nano for editing configuration files:
+
==Studio Broadcast dengan OBS==
  
pkg install nano
+
Kita bisa streaming menggunakan OBS, perlu di set
  
This streaming server will use the very powerful and versatile Nginx web server. You can build Nginx using the excellent ports system that FreeBSD boasts.
+
* Source > Media Sources > nama file.mp4
 
+
* File > Settings > Stream > Custom > Server dengan format di bawah ini (cek dengan ifconfig di server)
First, update your ports tree:
 
 
 
portsnap fetch
 
portsnap extract
 
 
 
Browse to the Nginx ports directory:
 
 
 
cd /usr/ports/www/nginx
 
 
 
And begin building Nginx by running:
 
 
 
make install
 
 
 
You'll see a screen asking what modules to include in your Nginx build. For this project, you'll need to add the RTMP module. Scroll down until the RTMP module is selected and press Space. Then Press Enter to proceed with the rest of the build and installation.
 
 
 
Once Nginx has finished installing, it's time to configure it for streaming purposes.
 
 
 
First, add an entry into /etc/rc.conf to ensure the Nginx server starts when your system boots:
 
 
 
nano /etc/rc.conf
 
 
 
Add this text to the file:
 
 
 
nginx_enable="YES"
 
 
 
stream-server_streamingconfig.png
 
 
 
==Nginx configuration==
 
 
 
Next, create a webroot directory from where Nginx will serve its content. I call mine stream:
 
 
 
cd /usr/local/www/
 
mkdir stream
 
chmod -R 755 stream/
 
 
 
Now that you have created your stream directory, configure Nginx by editing its configuration file:
 
 
 
nano /usr/local/etc/nginx/nginx.conf
 
 
 
Load your streaming modules at the top of the file:
 
 
 
load_module /usr/local/libexec/nginx/ngx_stream_module.so;
 
load_module /usr/local/libexec/nginx/ngx_rtmp_module.so;
 
 
 
stream-server_modules.png
 
Loading streaming modules
 
 
 
Under the Server section, change the webroot location to match the one you created earlier:
 
 
 
Location / {
 
root /usr/local/www/stream
 
}
 
 
 
stream-server_webroot.png
 
Changing webroot location
 
 
 
And finally, add your RTMP settings so Nginx will know how to handle your media streams:
 
 
 
rtmp {
 
        server {
 
                listen 1935;
 
                chunk_size 4096;
 
 
                application live {
 
                        live on;
 
                        record off;
 
                }
 
        }
 
}
 
 
 
Save the config. In Nano, you can do this by pressing Ctrl+X, Y, and then Enter.
 
 
 
As you can see, this is a very minimal config that will create a working streaming server. Later, you'll add to this config, but this will provide you with a great starting point.
 
 
 
However, before you can begin your first stream, you'll need to restart Nginx with its new config:
 
 
 
service nginx restart
 
 
 
Set up your streaming software
 
 
 
==Broadcasting with OBS==
 
 
 
Now that your server is ready to accept your video streams, it's time to set up your streaming software. This tutorial uses the powerful and open source Open Broadcast Studio (OBS).
 
 
 
Head over to the OBS website and find the build for your operating system and install it. Once OBS launches, you should see a first-time-run wizard that will help you configure OBS with the settings that best fit your hardware.
 
 
 
stream-server_autoconfig.png
 
OBS auto-configuration wizard
 
 
 
OBS isn't capturing anything because you haven't supplied it with a source. For this tutorial, you'll just capture your desktop for the stream. Simply click the + button under Source, choose Screen Capture, and select which desktop you want to capture.
 
 
 
Click OK, and you should see OBS mirroring your desktop.
 
 
 
Now it's time to send your newly configured video stream to your server. In OBS, click File > Settings. Click on the Stream section, and set Stream Type to Custom Streaming Server.
 
 
 
In the URL box, enter the prefix rtmp:// followed the IP address of your streaming server followed by /live. For example,
 
  
 
  rtmp://IP-ADDRESS/live.
 
  rtmp://IP-ADDRESS/live.
  
Next, you'll probably want to enter a Stream key—a special identifier required to view your stream. Enter whatever key you want (and can remember) in the Stream key box.
+
* Streaming Key, kita set sebagai password bagi user untuk akses, misalnya
  
stream-server_streamkey.png
+
x6kj-8psm-p2wy-38ks
Stream key setup
+
onno-teknik-jaringan
  
Click Apply and then OK.
+
Klik "Start Streaming" di OBS
  
Now that OBS is configured to send your stream to your server, you can start your first stream. Click Start Streaming.
+
==Settingan di sisi Client / Penonton==
  
If everything worked, you should see the button change to Stop Streaming and some bandwidth metrics will appear at the bottom of OBS.
+
Untuk bisa menonton, salah satu yang sederhana bisa menggunakan VLC
  
stream-server_metrics.png
+
sudo apt -y install vlc
OBS stream metrics
 
  
If you receive an error, double-check Stream Settings in OBS for misspellings. If everything looks good, there could be another issue preventing it from working.
+
Untuk akses, klik
  
==Viewing your stream==
+
* Media > Open Network Stream
  
A live video isn't much good if no one is watching it, so be your first viewer!
+
Alamat video streaming adalah
 
 
There are a multitude of open source media players that support RTMP, but the most well-known is probably VLC media player.
 
 
 
After you install and launch VLC, open your stream by clicking on Media > Open Network Stream. Enter the path to your stream, adding the Stream Key you set up in OBS, then click Play. For example,
 
  
 
  rtmp://IP-ADDRESS/live/SECRET-KEY.
 
  rtmp://IP-ADDRESS/live/SECRET-KEY.
  
You should now be viewing your very own live video stream!
+
==Selanjutnya?==
  
stream-server_livevideo.png
+
Yang bisa dikerjakan selanjutnya,
Live video in VLC
 
  
==Where to go next?==
+
* Limit access: bisa membatasi akses server kita, misalnya menggunakan firewall, .htaccess di web, atau access control di rtmp modul.
  
This is a very simple setup that will get you off the ground. Here are two other features you likely will want to use.
+
* Record streams: merekam video dengan cara mengubah sedikit konfigurasi,
 
 
    Limit access: The next step you might want to take is to limit access to your server, as the default setup allows anyone to stream to and from the server. There are a variety of ways to set this up, such as an operating system firewall, .htaccess file, or even using the built-in access controls in the RTMP module.
 
 
 
    Record streams: This simple Nginx configuration will only stream and won't save your videos, but this is easy to add. In the Nginx config, under the RTMP section, set up the recording options and the location where you want to save your videos. Make sure the path you set exists and Nginx is able to write to it.
 
  
 
  application live {
 
  application live {
Line 252: Line 101:
 
               record_unique on;
 
               record_unique on;
 
  }
 
  }
 
The world of live streaming is constantly evolving, and if you're interested in more advanced uses, there are lots of other great resources you can find floating around the internet. Good luck and happy streaming!
 
 
 
 
 
 
  
 
==Referensi==
 
==Referensi==

Latest revision as of 10:35, 11 May 2020

Sumber: https://opensource.com/article/19/1/basic-live-video-streaming-server

Yang perlu di pikirkan dalam instalasi live streaming video server

  • Stream quality: mau HD atau SD?
  • Viewership: jumlah pemirsa?
  • Storage: mau di rekam atau tidak?
  • Access: apakah private atau open?

Spec Minimal Server:

  • 4GB RAM
  • 20G harddisk
  • 1 core i7

Disini digunakan Real-Time Messaging Protocol (RTMP) untuk menangani audio + video streaming. Alternatif lain adalah WebRTC.

Setting Server

Instalasi nginx

sudo apt update
sudo apt upgrade (optional)
sudo apt -y install nginx

Instalasi RTMP agar nginx dapat menangani media stream:

sudo add-apt-repository universe
sudo apt install libnginx-mod-rtmp

Tambahkan konfigurasi di nginx untuk menangani RTMP,

sudo vi /etc/nginx/nginx.conf

Tambahkan di paling bawah,

rtmp {
        server {
                listen 1935;
                chunk_size 4096; 

                application live {
                        live on;
                        record off;
                }
        }
}

Di save konfigurasi-nya.

Restart nginx

sudo systemctl restart nginx
/etc/init.d/nginx restart



Studio Broadcast dengan OBS

Kita bisa streaming menggunakan OBS, perlu di set

  • Source > Media Sources > nama file.mp4
  • File > Settings > Stream > Custom > Server dengan format di bawah ini (cek dengan ifconfig di server)
rtmp://IP-ADDRESS/live.
  • Streaming Key, kita set sebagai password bagi user untuk akses, misalnya
x6kj-8psm-p2wy-38ks
onno-teknik-jaringan

Klik "Start Streaming" di OBS

Settingan di sisi Client / Penonton

Untuk bisa menonton, salah satu yang sederhana bisa menggunakan VLC

sudo apt -y install vlc

Untuk akses, klik

  • Media > Open Network Stream

Alamat video streaming adalah

rtmp://IP-ADDRESS/live/SECRET-KEY.

Selanjutnya?

Yang bisa dikerjakan selanjutnya,

  • Limit access: bisa membatasi akses server kita, misalnya menggunakan firewall, .htaccess di web, atau access control di rtmp modul.
  • Record streams: merekam video dengan cara mengubah sedikit konfigurasi,
application live {
             live on;
             record all;
             record_path /var/www/html/recordings;
             record_unique on;
}

Referensi

Pranala Menarik