How to work with media server?

Real-time publish or play in VideoIO requires a media server. The VideoIO project is compatible with RTMP-based media server. VideoIO has been tested successfuly with Adobe's Flash Media Server (FMS) and Open Source Flash RTMP server in Python (rtmplite). Adobe's FMS comes in two flavors, but for real-time interactive communication, you need to use the more expensive Flash Media Interactive Server. VideoIO should also work with other media servers such as Open Source Red5 and commercial Wowza. This article is not an endorsement of one media server product over another. However, we will use rtmplite for illustrating examples in this document.

Typically, an RTMP-based media server allows publish and playback of media stream. A Flash application uses ActionScript NetConnection and NetStream objects to initiate an RTMP connection from Flash Player to the media server, and open publish or play media stream. The connection is made using an rtmp URL, e.g., "rtmp://server/myapp/some/path". The URL path, /myapp/some/path, identifies the scope, where the first item, /myapp, usually refers to an application, and subsequent ones, /some/path, refer to specific scope. Typically, all the clients connected to the same URL are within the same application scope, and can share the media streams. However, media streams within different scopes are independent of each other. Media servers allow programmable server side scripts to control the behavior of the connection and media stream, e.g., to authenticate the connection. In Adobe's FMS, you need to explicitly create a server-side application directory to enable a specific application, e.g., myapp, whereas rtmplite can dynamically create default application when new connections are received.

The default application behavior is to allow live chat as well as recording, as directed by the clients. If two clients are connected to the same URL, and within the same application scope, and one client publishes as stream named "stream1" then other client can play that stream by name. Similarly, the first client can play another stream named "stream2" published by the second client. This enables two-party video call between the two clients via the media server. Similarly, a media stream can be recorded by a client by stream name, and later played by another client by that same stream name, to facilitate video messaging. The media server typically stores a recorded media stream in an FLV video file. You design your server architecture to serve the recorded media files via a web server to make the playback independent of the media server. This is typically useful for record-once and play-many type of video resources.

What is rtmplite? It is a Python implementation of the Flash RTMP server with minimal support needed for real-time streaming and recording. Three main advantages are (1) it is really light weight with only a few Python files and quick to get started, (2) it interoperates with SIP/RTP standards based VoIP, and allows you to quickly set up PC-to-phone call systems, (3) it is written in Python and hence portable across several systems including Windows, Mac OS X, Linux, without having to re-compile. The main disadvantage is that it does not support AMF3 and advanced features such as remote SharedObject. Please see https://github.com/theintencity/rtmplite for details.

In this article, we will go over setting up rtmplite as your media server on your local host so that it can be easily tested with your VideoIO based application. Eventually, in your deployment of VideoIO application you can use other media servers and replace localhost in the URLs with the host name of your media server.

First download the latest version of the rtmplite software, and go over the instructions to install it on your local machine. At the time of writing this article, version 6.0 is the lastest, and depends Python 2.6. If you do not have Python 2.6 installed, you will need to install that first. After that running the rtmplite server is as simple as running the following commands:

$ tar -zxvf rtmplite-6.0.tgz
$ cd rtmplite
$ python rtmp

Alternatively, you can use -d command line option for the last command above, to enable debug trace on standard output.

As mentioned before, by default rtmplite accepts connection to any application scope, and treats all applications as default which allows live chat, recording and playback. Suppose your local machine's IP address is 192.1.2.3, then connecting to "rtmp://192.1.2.3/myapp/some/path" from Flash Player will connect to the "myapp" application with scope "/some/path" on the server. If you record a media stream with name "stream1", the server will create the file "some/path/stream1.flv" in the current directory to store the recorded media stream. In our tutorial, we will run VideoIO application on the same machine as our rtmplite server hence will use the URL of the form "rtmp://localhost/myapp/some/path".

This is all the information you need to get started with rtmplite as your media server to test against your VideoIO application. Interested readers should explore more on the rtmplite software such as its command line options, how to interconnect with SIP-based systems, and how to use the command line rtmpclient for testing.