Setup RTMP server in Docker
In this post we will demonstrate how Niostreamer can be configured as RTMP server to be able receive incoming RTMP connections and play RTMP streams. In this post will be shown how to create Virtual Host to listen to clients.
If you haven't installed Niostreamer yet please read corresponding documentation section here: https://niostreamer.com/documentation/install
In this tutorial we will use official Niostreamer Docker image located here: https://hub.docker.com/r/niostreamer/niostreamer
We expect that Docker is already installed on your local machine so we will spent time fo it. If not, pelase read Docker documentation first.
Niostreamer instance will be started using docker-compose functionality. To do it, let's prepare
/home/user/niostreamer/docker-compose.yml we will use to start niostreamer with the following content:
ports section. Here, port 8080 is REST API HTTP port niostreamer uses for internal needs. 1935 is a TCP port for RTMP streaming. When started this port is not opened as there are no virtual host registered yet. Once we add niostreamer instance to control panel the instance will open 1935 port.
volumes section we mount configuration and logs directories.
mkdir -p /home/user/niostreamer/conf
mkdir -p /home/user/niostreamer/conf/conf.d
mkdir -p /home/user/niostreamer/log
Create configuration file
/home/user/niostreamer/conf/niostreamer.conf with the following content:
listen = "0.0.0.0";
port = 8080;
file = "";
level = "info";
workers = 1;
You can change number of workers according to number of CPU cores on your machine.
Run niostreamer from the directory with
docker-compose.yml you previously created:
You will see niostreamer is started:
Starting niostreamer_niostreamer_1 ... done
Attaching to niostreamer_niostreamer_1
niostreamer_1 | 2021-06-26 16:27:51.663875 info Niostreamer version: 0.0.252
niostreamer_1 | 2021-06-26 16:27:51.664483 info [geoip] File /etc/niostreamer/conf.d/GeoLite2-Country.mmdb does not exist. Skipping
niostreamer_1 | 2021-06-26 16:27:51.664516 info [geoip] File /etc/niostreamer/conf.d/GeoLite2-ASN.mmdb does not exist. Skipping
niostreamer_1 | 2021-06-26 16:27:51.665099 info [saas] Instance status: registered in web control panel
niostreamer_1 | 2021-06-26 16:27:51.665355 info [http-server] server started: 0.0.0.0:8080
niostreamer_1 | 2021-06-26 16:27:51.665438 info [core] VHost 'http-instance-api' started
It opens API 8080 port, but it still knows nothin about 1935, we must tell directly niostreamer to start RTMP server.
Since niostreamer is up and running the next step is to configure RTMP virtual host. Virtual host is technically a server machinery that provides functionality for the specific protocol. When you create a virtual host niostreamer opens a network port to start recieving incoming connections from clients.
As mentioned earlier, in this tutorial we will create RTMP virtual host.
The Niostreamer instance must be registered in control panel to do that.
Using web control panel you can control all aspects of fuctionality your RTMP or HLS servers, you can monitor instance staitstics using web browser or mobile.
Please create a new account on niostreamer website: https://niostreamer.com/console/register
Sign into your account. You will see empty dashboard, because there are no server instances registered yet: https://niostreamer.com/console/instances
On this page you will see the example of curl command line utility demonstrates how to register instance in control panel. Niostreamer has special API on HTTP port 8080 to do that.
Run the following command in other window to register instance in control panel:
curl -X POST http://localhost:8080/api/v1/saas/instances/register \
-H "X-Account-Key: AA1SXUJHBWT277LNMM6P" \
-H "X-Account-Secret: 2ibhtnyHRCetYkOh9r5IoYZqPcZ0oBj8DJrO5Sb8"
You will see in logs that instance has been registered:
And then you will see the new instance in web panel as well:
Now Niostreamer is ready to accept incoming connections from RTMP clients.
Create RTMP virtual host
In instance overview page press "Add Virtual Host" button
Enter virtual host and port and press "Save"
To start virtual host the listener interface must be created. Open Virtual host page and press "Add Listener"
Enter listening address and port and press "Add"
Wait a little bit until instance is syncronized with control panel. You'll see the virtual host is started in streamer logs:
niostreamer_1 | 2021-06-28 05:22:00.351304 info [live-stream-manager] Application 'live' registered
niostreamer_1 | 2021-06-28 05:22:00.351333 info [core] VHost 'rtmp-default' started
Niostreamer has opened TCP port 1935 and is ready to listen for incoming connections.
As a test stream we will use command line utility
ffmpeg. We will try to stream popular video sample used to test video streams called "Big Buck Bunny".
Start the command from your machine:
ffmpeg -re -i C:/video/big-buck-bunny.mp4 -vcodec copy -acodec copy -f flv rtmp://vm.local:1935/live/bunny
Streaming is started now. niostreamer started to receive audio video data. Let's play incoming stream using
ffplay -f flv "rtmp://vm.local:1935/live/bunny" -v verbose
You will see video window playing the target sample.
Niostreamer is a fully functional streaming server. It can convert incoming RTMP streams to other ones, i.e. HLS.
In next articles we will show how to stream RTMP to niostreamer and the share it as HLS to other players.