Nginx: 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
- 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.
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!