Live streaming is in much demand nowadays. Kaltura first introduced an end to end live streaming solution back in 2013.
The Kaltura Live Streaming mechanism makes use of the Wowza streaming engine [https://wowza.com] and the code for Kaltura’s side of things can be found here: https://github.com/kaltura/media-server
Wowza’s software is well established and it definitely works. That said, Kaltura’s Core Platform is a FOSS project and as such, we’re always looking to integrate with other FOSS projects. For that reason, I became quite interested in FOSS alternatives to Wowza. A quick search led me to a great FOSS project called nginx-rtmp-module [https://github.com/arut/nginx-rtmp-module].
I am no stranger to Nginx, in fact, we make use of it in another critical project we created and maintain – The Nginx VOD module [https://github.com/kaltura/nginx-vod-module]. Nginx is free and open source software, released under the terms of a BSD-like license, which makes it easy to integrate with.
I could easily dedicate an entire post to the advantages of FOSS but plenty others have done a fine job at articulating that and this is not today’s topic so I think I’ll settle for: FOSS RULES! and move on.
The FOSS live streaming solution I’m about to detail in this post consists of the following main components:
– Nginx [BSD]
– Nginx RTMP Module [BSD]
– FFmpeg [GPL]
– Kaltura Server [AGPLv3]
– Kaltura HTML5 Player [AGPLv3]
Installation
Installing Kaltura CE [Community Edition] is easy. We ship both RPM and Deb packages and installation instructions can be found here:
https://github.com/kaltura/platform-install-packages/#documentation-and-guides
The kaltura-server meta package declares all required dependencies and so, for a single server deployment, issuing:
# $YOUR_FAVOURITE_PACKAGE_MANAGER install kaltura-server
should do the trick.
Important note: the setup detailed in this post requires Kaltura CE of version 12.4.0 or higher [current stable version is 12.8.0].
The Kaltura Player package should be of version v2.48.1 [or higher] and the kaltura-nginx package should be of version 1.10.2 [or higher].
Below is a very partial listing of dependencies that will be fetched and installed when running “`$YOUR_FAVOURITE_PACKAGE_MANAGER install kaltura-server“`.
Those who want the cake, not the recipe, can skip this section and go right to the “Nginx RTMP Configuration” section.
– kaltura-nginx: Nginx is available in the official repos of many Linux distributions. The reason we package our own rather than use the official distros package is that Nginx only introduced DSO [Dynamic Shared Objects] support starting from version 1.9.11 [https://www.nginx.com/blog/dynamic-modules-nginx-1-9-11]. Before that, if you wanted to include additional modules, it had to be done statically during build time. Since we need both the nginx-rtmp-module and nginx-vod-module, releasing our package was the only viable option. As mentioned before, Kaltura CE is a completely FOSS project and that includes the package specs, the ones used for Nginx can be found here:
https://github.com/kaltura/platform-install-packages/blob/Lynx-12.9.0/RPM/SPECS/kaltura-nginx.spec
https://github.com/kaltura/platform-install-packages/tree/Lynx-12.9.0/deb/kaltura-nginx/debian
– kaltura-base: includes the Kaltura Server code which lives in this repo: https://github.com/kaltura/server
– kaltura-front: a meta package declaring all dependencies needed to run a Kaltura frontend server [Kaltura Management Console, Kaltura’s HTML5 player, FFmpeg and so on]
Nginx RTMP Configuration
The paths to the configuration files for kaltura-nginx vary depending on rather you use the Deb or the RPM package.
For deb, the main file is here:
/opt/kaltura/nginx/conf/nginx.conf
For RHEL:
/etc/nginx/nginx.conf
As noted previously, the Nginx shipped with the kaltura-nginx package includes the nginx-rtmp-module which in this solution is used for both the streaming and delivery. Here is the basic RTMP module configuration shipped with kaltura-nginx:
Build your own live video stream on Kaltura’s APIs
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
# This application is to accept incoming stream
application kLive {
live on; # Allows live input from above
dash on; # create DASH fragments and manifest
dash_path /var/tmp/dashme; # Sets MPEG-DASH playlist and fragment directory
hls on; # create HLS fragments and manifest
hls_cleanup on;
hls_sync 100ms;
hls_fragment 2s;
hls_path /var/tmp/hlsme/; # Sets HLS playlist and fragment directory
}
}
}
Creating a Live Stream Entry
Next, we need to create the Kaltura Live Entry that will make use of the HLS stream, this is done by going to KMC->Upload->Live Stream Entry.
For Live Stream Type, select “Manual Live Stream URLs”, provide a meaningful name for the entry, for example “My Live Test”, and input “https://$YOUR_NGINX_HOST:$NGINX_PORT/hlsme/$DESIRED_STREAM_NAME.m3u8” in the “HLS stream URL” text box.
$YOUR_NGINX_HOST is the hostname/FQDN of the machine you installed the kaltura-nginx package on, you can of course place one or more such nodes behind a load balancer. In such a case, it will be the LB’s address. Note that when using more than one node, you need to make sure hls_path points to a location accessible to all Nginx nodes.
When installing the kaltura-nginx package, the default $NGINX_PORT is 88, this can be changed during the post install configuration script, if you’re unsure, check the value for the listen directive in the http->server section in nginx.conf, this is not to be confused with the listen directive in the rtmp section, which is set to 1935 [RTMP] by default.
$DESIRED_STREAM_NAME can be any string you’d like.
Streaming
There are several commercial tools for RTMP streaming, perhaps the most common of these is Adobe’s FMLE. While FMLE can certainly be used, in the spirit of FOSS, we will use the ffmpeg CLI binary to stream. Kaltura makes heavy use of FFmpeg in its transcoding mechanism so every Kaltura Server includes our own build of ffmpeg, provided by the kaltura-ffmpeg package. If you’d rather stream from your desktop and that desktop is not running Linux, you can get ffmpeg binaries for your OS here:
https://ffmpeg.org/download.html
Here is the ffmpeg command to use:
$ ffmpeg -re -i /path/too/your/video/file -c copy -f flv "rtmp://$YOUR_NGINX_HOST:$YOUR_NGINX_RTMP_PORT/kLive/$DESIRED_STREAM_NAME"
Testing playback
Now, all that’s left is playing the stream. Go to KMC->your Live Stream Entry->Actions->Preview & Embed, select your HTML5 player from the list and hit play:)
In the same view, you will also find the HTML code needed to embed the player onto external websites.
Conclusion and next steps
In this brief tutorial, we’ve detailed how to achieve a completely free and open live video streaming solution.
An important next step is to restrict publishing access [and perhaps playback too, depending on your needs]. To that end, see https://github.com/arut/nginx-rtmp-module/wiki/Directives#access
The Nginx RTMP module also supports many additional, well documented options that are worth exploring:
https://github.com/arut/nginx-rtmp-module/wiki/Directives
In the future, we plan to achieve a deeper level of integration between Kaltura and the Nginx RTMP module and allow for DVR and automatic stream provisioning.
As always, we are happy to get feedback and code contributions from the community. As noted before, the package specs, install scripts and configuration files can all be found here: https://github.com/kaltura/platform-install-packages/, for contribution guidelines, see: https://github.com/kaltura/platform-install-packages/blob/master/doc/Contributing-to-the-Kaltura-Platform.md
Credit where credit is due
My deepest thanks to the Nginx and FFmpeg projects and to Roman Arutyunyan for creating the Nginx RTMP module project.
Start building your video application and experience the full power of the Video Cloud!