This is a Docker image to compile, configure and serve NGINX 1.19.6 with the RTMP module to support authenticated and encrypted RTMP/RTMPS media stream as intake, and broadcast HLS and MPEG-Dash streams to multiple simultaneous users on the internet.
Check out this blog post for more information about it.
Warnings
-
I've created a dummy SSL certificate/key pair and included it on
./ssl
. Be sure to use a different/real one if you're going to run this on production. -
Be sure to edit the
$arg_streamkey
and$arg_watchkey
values on thenginx.conf
file, so it will use your own secret "stream key" and "watch key". The default$arg_streamkey
is5f3e32f3bad0
, and the$arg_watchkey
is16356b9f
. -
Mind that you will have to rebuild the image for those changes to take effect.
Build the image:
$ docker-compose build broadcaster
Turn on the NGINX server:
$ docker-compose up broadcaster
This will bind the 4080
, 4443
, 4080
and 4936
ports to your host machine, so the host will act as the NGINX server.
The address to stream follows the format:
<protocol>:<nginx-server-address>:<port>/live/<media-name>?streamkey=<stream-key>
<protocol>
: Eitherrtmp
orrtmps
.<nginx-server-address>
: The IP/DNS of the NGINX server.<port>
: Use4935
forrtmp
, and4936
forrtmps
.<media-name>
: Choose a unique URL-compliant name.<stream-key>
: The streaming key, defaults to5f3e32f3bad0
.
Examples:
rtmps:192.168.1.192:4936/live/myvideo?streamkey=5f3e32f3bad0
rtmp:192.168.1.192:4935/live/othervideo?streamkey=5f3e32f3bad0
Over RTMP:
$ ffmpeg \
-stream_loop -1 \
-i sample.mp4 \
-f flv "rtmp:192.168.1.192:4935/live/testing?streamkey=5f3e32f3bad0"
Over RTMPS:
$ ffmpeg \
-stream_loop -1 \
-i sample.mp4 \
-f flv "rtmps:192.168.1.192:4936/live/testing?streamkey=5f3e32f3bad0"
Over RTMP:
ffmpeg \
-f video4linux2 -framerate 25 -video_size 1280x720 -i /dev/video0 \
-f alsa -ac 2 -i sysdefault:CARD=WEBCAM \
-c:v libx264 -b:v 1600k -preset ultrafast \
-x264opts keyint=50 -g 25 -pix_fmt yuv420p \
-c:a aac -b:a 128k \
-vf "drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: \
text='CLOUD DETECTION CAMERA 01 UTC-3 %{localtime\:%Y-%m-%dT%T}': fontcolor=white@0.8: fontsize=16: x=10: y=10: box=1: boxcolor=black: boxborderw=6" \
-f flv "rtmp:192.168.1.192:4935/live/mycam?streamkey=5f3e32f3bad0"
Over RTMPS:
ffmpeg \
-f video4linux2 -framerate 25 -video_size 1280x720 -i /dev/video0 \
-f alsa -ac 2 -i sysdefault:CARD=WEBCAM \
-c:v libx264 -b:v 1600k -preset ultrafast \
-x264opts keyint=50 -g 25 -pix_fmt yuv420p \
-c:a aac -b:a 128k \
-vf "drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: \
text='CLOUD DETECTION CAMERA 01 UTC-3 %{localtime\:%Y-%m-%dT%T}': fontcolor=white@0.8: fontsize=16: x=10: y=10: box=1: boxcolor=black: boxborderw=6" \
-f flv "rtmps:192.168.1.192:4936/live/mycam?streamkey=5f3e32f3bad0"
For the .mp4 file example, this would be the secure HLS watching address:
https://192.168.1.192:4443/hls/testing.m3u8?watchkey=16356b9f
And this would be the MPEG-Dash one:
https://192.168.1.192:4443/dash/testing.mpd?watchkey=16356b9f
But you can also watch them without end-to-end encryption:
HLS - http://192.168.1.192:4080/hls/testing.m3u8?watchkey=16356b9f
Dash - http://192.168.1.192:4080/dash/testing.mpd?watchkey=16356b9f
However I don't recommend using this for production. Mind the stream and watch keys will be sent as plain-text on such connections.
You can insert these addresses (changing to match your server IP) on the VLC network stream connection address input (Ctrl + n
) to watch the stream. All HLS and Dash clients are supported, check for one on your application store if you don't want to use VLC.
It also works on the browser, check for Web/JavaScript HLS and Dash clients; I recommend checking Google's Shaka Dash player.
Here follows a more complete information about these addresses.
The HLS watching address follows the format:
<protocol>://<nginx-server-address>:<port>/hls/<media-name>.m3u8?watchkey=<watch-key>
<protocol>
: Eitherhttp
orhttps
.<nginx-server-address>
: The IP/DNS of the NGINX server.<port>
: Use4080
forhttp
, and4443
forhttps
.<media-name>
: Themedia-name
of the stream.<watch-key>
: The watching key, defaults to16356b9f
.
Examples:
https://192.168.1.192:4443/hls/myvideo.m3u8?watchkey=16356b9f
http://192.168.1.192:4080/hls/othervideo.m3u8?watchkey=16356b9f
The Dash watching address follows the format:
<protocol>://<nginx-server-address>:<port>/dash/<media-name>.mpd?watchkey=<watch-key>
<protocol>
: Eitherhttp
orhttps
.<nginx-server-address>
: The IP/DNS of the NGINX server.<port>
: Use4080
forhttp
, and4443
forhttps
.<media-name>
: Themedia-name
of the stream.<watch-key>
: The watching key, defaults to16356b9f
.
Examples:
https://192.168.1.192:4443/dash/myvideo.mpd?watchkey=16356b9f
http://192.168.1.192:4080/dash/othervideo.mpd?watchkey=16356b9f
These configuration files are available as open source under the terms of the MIT License.