How to setup FLV streaming with crtmpserver C++ RTMP server

Saturday October 08, 2011 ()

crtmpserver is a high performance real time media streaming server able to stream recorded or live media. Today we will demonstrate how to build and use crtmpserver to stream FLV and other audio and video formats (see table near the end of page) in Debian 6 server. We intend not to modify the source, so there is no C++ programming involved.

First we make sure we have the build tools we need.

apt-get update
apt-get install build-essential libssl-dev cmake subversion

Fetch the source code through subversion.

svn co --username anonymous https://svn.rtmpd.com/crtmpserver/trunk rtmp
[enter] #password should be empty

rtmp at the end of line 1 above is the name of the directory where the source files are checked out to relative to your current directory. For example if your current directory is /home/folder, rtmp will be created in this location and so the final path will be /home/folder/rtmp.

Issue the following commands to start building the source.

cd rtmp/builders/cmake

cmake -DCMAKE_BUILD_TYPE=Release .
make

cmake builds our Makefiles, make create our binaries using Makefiles created by cmake. Notice the dot [.] after cmake. If you plan to install the binaries somewhere else, issue the commands that follow instead of the above. In the cmake command below install-dir is the path where you want the binaries installed.

cmake -DCMAKE_BUILD_TYPE=Release -DCRTMPSERVER_INSTALL_PREFIX=<install-dir>
make
make install

The build process will create our crtmpserver server executable and a ready to use configuration file named crtmpserver.lua. crtmpserver and the configuration file are saved in [current-directory]/[check-out-directory]/builders/cmake/crtmpserver. This configuration file consists of two main sections, the logAppenders and applications sections. For FLV streaming, the default configuration has already an appselector and an application ready for use. All we need is to change the location of our media files. But first let us test if our build works.

Issue the following command from where you issued make.

crtmpserver/crtmpserver crtmpserver/crtmpserver.lua

If you have installed crtmpserver somewhere else, access crtmpserver from that install location and enter the location of the configuration file in the first (and only) parameter.

If you moved the configuration file, you should also change the value of rootDirectory. rootDirectory is defined in the configuration file, its default value is "applications" directory. The applications directory is located in the cmake directory.

If there were no errors you should see a list of applications, ports and other applications details. Press ctrl-c to exit.

Configuration

Change the default media location to a desired location where you want to store your FLV files. Below is the section of crtmpserver.lua that needs to be modified for the mediaFolder.

  description="FLV Playback Sample",
  name="flvplayback",
  protocol="dynamiclinklibrary",
  mediaFolder="/home/primo/media/",
  aliases=
  {
     "simpleLive",
     "vod",
     "live",
     "WeeklyQuest",
     "SOSample",
     "oflaDemo",
  },

You may also want to change the loglevel from the logAppenders section. The default is log level is 6. That is the highest log level which logs everything into a file also defined in the logAppenders section. Log level values can be from 1 to 6.

 {
    name="file appender",
    type="file",
    level=6,
    -- the file where the log messages are going to land
    fileName="/tmp/crtmpserver",
    --newLineCharacters="\r\n",
    fileHistorySize=10,
    fileLength=1024*256,
    singleLine=true
 }

crtmpserver can be run as a deamon or as a normal application. crtmpserver runs as normal application by default. To run it as a daemon, locate daemon=false near the beginning of the configuration file and change the value to true. You can also use the command line option --deamon to this effect.

crtmpserver/crtmpserver --help

If you are running behind a firewall you should open up some ports especially the appSelector port.

Live Test

For our test we use JWplayer which can be downloaded here

<html>
  <head>
     <title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     <script type="text/javascript" src="./player/jw/swfobject.js" />
  </head>
  <body>
     <div id="media">player will be  here</div>

     <script type='text/javascript'>
        var so = new SWFObject('./player/jw/player.swf','mpl','640','360','9');
        so.addParam('allowfullscreen','true');
        so.addParam('allowscriptaccess','always');
        so.addParam('wmode','opaque');
        so.addVariable('file','sample');
        so.addVariable('streamer','rtmp://ur-domain.com/flvplayback/');
        so.write('media');
     </script>
  </body>
</html>

Change ur-domain.com to your domain or IP address.

flvplayback is our application set in our crtmpserver.lua configuration. Our media file is sample.flv and can be entered with or without the extension. sample.flv is stored in our mediaFolder directory we set in our configuration file.

The following are the audio and video types/formats supported by the default flvplayback application per documentation that come with the source.

Type Naming/Access Name File
mp3 mp3:file_name file_name.mp3
flv file_name (or file_name.flv) (*) file_name.flv
mp4 mp4:file_name.mp4 (*) file_name.mp4
m4a mp4:file_name.m4a file_name.m4a
m4v mp4:file_name.m4v file_name.m4v
mov mp4:file_name.mov (*) file_name.mov
f4v mp4:file_name.f4v file_name.f4v

(*) - Tested and works

To further configure the player see the JWplayer website.

Unlike psuedo HTTP streaming we don't need to enject metadata to FLV files.

You may also want to visit crtmpserver website for additional read.

That's it. Good luck.

(Go to top of page)


34,111

Comments (How to setup FLV streaming with crtmpserver C++ RTMP server)