Nginx: Basic Live Video Streaming Server

From OnnoWiki
Revision as of 09:50, 11 May 2020 by Onnowpurbo (talk | contribs)
Jump to navigation Jump to search

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



Broadcasting with 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



Viewing your stream

A live video isn't much good if no one is watching it, so be your first viewer!

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.

You should now be viewing your very own live video stream!

stream-server_livevideo.png Live video in VLC

Where to go next?

This is a very simple setup that will get you off the ground. Here are two other features you likely will want to use.

   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 {
             live on;
             record all;
             record_path /var/www/html/recordings;
             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

Pranala Menarik