Flash Media Server 4 brings Multicast to Flash Video

In case you missed it Adobe announced Flash Media Server 4 . This is a significant release for a number of reasons. The first reason is that many corporate customers have been interested in Flash video but were not able to take advantage of it with out support for IP Multicast as this technology was a mandate from their IT organization. In other words this update for the Flash Media Server to version four gets you a 64bit architecture, Absolute timecode, faster seeking, trick mode playback (fast motion, slow motion, and frame stepping), intelligent reconnect, faster switching for RTMP Dynamic Streaming and IP Multicast Support.

Using version 4  of the interactive edition of the Flash Media Server gets you the ability to choose between Unicast (with or with out Origin / Edge), IP Multicast and even Live HTTP Dynamic Streaming. It is even possible to failover from IP Multicast to a Unicast stream if necessary. When you consider all of the possibilities they include:

  • Interactive applications that support video, audio and data for one to many and many to many for both live and video on demand
  • Large scale broadcasts using IP Multicast
  • Origin / Edge solutions that can be used to intelligently reduce bandwidth requirements for vod
  • Failover for complex environments with different network requirements (e.g. remote sites, vpn)

That is a short summary of the possibilities that you get with the interactive edition of the Flash Media Server but that was not the only announcement. Adobe also announced Adobe® Flash® Media Enterprise Server 4. If you are not familiar with RTMFP that would be a good place to start. This peer protocol will allow you to take advantage of users / viewers upstream bandwidth to broadcast video, audio and data in your application and now the Flash® Media Enterprise Server 4 can participate in those groups. So consider the limitations of a peer broadcast. First you will only have access to the one video codec that can encode that is part of the Flash Player and that is Sorenson Spark. If you are familiar with Sorenson Spark you know that the quality leaves something to be desired. When you consider that the Flash® Media Enterprise Server 4 can act as a peer using RTMFP you now have access to all of the varied video formats that can be broadcast using the server (On2, H.264,…). It is also important to note that you are not limited to just video when you are using Peer Assisted Multicast (RTMFP) you can include data as well. These applications can include interactivity unlike IP Multicast. Of course there are considerations that include additional latency based on the number and location of peers in a group but the possibilities are amazing. Just consider an internet based application that includes video and interactivity with 10k concurrent users. With out a peer solution you would have to invest in a significant number of servers as well as a significant amount of bandwidth. With the Flash® Media Enterprise Server 4 you could address both server and bandwidth requirements with a small fraction of what it would take with a Unicast solution. The cost savings will be significant.

Test Media Player

After numerous calls to help people confirm that the server was working correctly I decided to write a media player that would help test and confirm the ability to stream video from the Flash Media Server. This player is provided as is with no warranty or support but I hope you will find it useful. This is an AIR based player.  I created it for AIR for a number of reasons not the least of which that it was easy to install and run locally with out the need for an http server. I have already thought of a few additions so let me know if you find it useful. It is simple to use, just enter the url to some media on an FMS server in the following form:

URL Syntax: rtmp://[servername]/[application]/[streamname+extension]

1)     [servername]: this is the IP Address, or the domain name of your server. (i.e. localhost)
2)     [application]: use “vod” unless you have created a new directory in the application folder of the Flash Media Server installation directory. There are two built in applications vod and live.
4)   [streamname]: use the name of your video file (including the extension). The extension can be flv, f4v or mp4. You do not need to prefix the file name with the content type (e.g. mp4:).

The application reports Current Bitrate, Dropped Frames as well as Max Bytes Per Second and other useful messages. When you stop the video you will be presented with a graph and grid of the captured data.

AIR Test Media Player
AIR Test Media Player

You can download the application here.

Flash Media Server Configuration Limiting Bandwidth

Overview:
This will most likely turn into a series but I had to start some where. In this article I am going to cover a topic that comes up regularly, configuring the Flash Media Server to support multiple networks with different bandwidth capabilities. To be more clear imagine a central data center with the Flash Media Server installed and multiple remote locations with constrained bandwidth connections to the data center. How do you limit the amount of bandwidth consumed by one location with out limiting every other location?

The first thing to be aware of is that the Flash Media Server is very configurable. With a single server installation you can serve multiple networks with multiple virtual hosts that each have their own configuration. These configurations are handled by editing xml configuration files and creating directories in the conf directory of the Flash Media Server installation folder. For this article I am going to focus on creating a virtual host for each remote site and assume that we do not need multiple adapters. The configuration guide gives the following guidance regarding virtual hosts and adaptors:

“You can assign an IP address or a port number to an adaptor, but not to a virtual host. For this reason, use adaptors to organize virtual hosts by IP address or port number. For example, if a virtual host needs its own IP address to configure SSL, assign it to its own adaptor.”

Getting Started:
The process of creating a virtual host is fairly easy. First you locate the conf directory in the Flash Media Server installation directory.  Then create a folder with the name of the virtual host inside conf/_defaultRoot_/. This name is important as it will be the name you use to create a DNS entry. A DNS entry is required so that all requests coming to the server with that name are directed to the appropriate virtual host. If you are setting up a development environment (this will not work in production) you can use a the host file to map the virtual host name (e.g. http://www.first.com) to the local ip address (e.g. 127.0.0.1).  In my host file I have the following entry:

127.0.0.1       http://www.first.com

If I had two virtual hosts setup (www.first.com and http://www.second.com) the DNS entry is used to direct the requests to the appropriate virtual host even though they are on the same server with a single instance of the Flash Media Server installed. To elaborate that would mean that I would have two folders in the conf/_defaultRoot_/ directory the first would be http://www.first.com and the second would be http://www.second.com.

Flash Media Server Directory for vhost
Flash Media Server Install Directory and vhost folders

Once the folders are created you will copy the Application.xml and the vhost.xml file from conf\_defaultRoot_\_defaultVHost_ and paste copies into both the http://www.first.com folder and the http://www.second.com folder. The Users.xml file is required only if you are defining administrators for this virtual host. Finally you will specify the location of the application directory for each virtual host in the vhost.xml file. This is required to avoid namespace conflicts. The application directory will hold the server side script and optionally content if you want different content for each virtual host. You can think of the application directory that you just created as being synonymous with the vod and live directory in the top level of the application folder in the Flash Media Server installation folder. The entry in the vhost.xml file to setup an application directory (you have to do this for each virtual host) should look something like the following:

<AppsDir>C:\myvhostApplications\first</AppsDir>

Notice that I do not have to use the name of the vhost folder (www.first.com) this is simply the location where we will  store server side script and or content. For the sake of completeness, for the vhost.xml file in the http://www.second.com folder inside  conf/_defaultRoot_/ you would have an entry similar to the following:

<AppsDir>C:\myvhostApplications\second</AppsDir>

The applications directory is the base directory where all applications for this virtual host is defined. You can store the video files in these directories but since the goal of this article is to show how to limit bandwidth it is assumed that each location would want access to the same content. If that was not the case you could simply create a sub folder streams and an other folder called _defInst (default instance) for each of the following and put the content for that virtual host inside that directory.

C:\myvhostApplications\first

C:\myvhostApplications\second

directory listing for the vhost application and content
vhost application and content directories

The goal of this example is to serve multiple vhosts which will serve multiple locations with varying bandwidth limits with the same content available for each virtual host. We will use the settings in the vhost.xml file to limit the number of streams available for each virtual host.

In order to limit the total number of connections from a given location to a virtual host on the Flash Media Server we will use the MaxConnections setting found in the vhost.xml file of each virtual host. In other words inside the http://www.first.com folder inside conf\_defaultRoot_ you will find the vhost.xml file with the MaxConnections setting.

<MaxConnections>-1</MaxConnections>

By default it is set to -1 which means unlimited. You can set this to what ever number makes sense for your circumstance.

It will also be a good idea to disconnect idle viewers so that after a specified idle time some else can view content. This is also handled in the vhost.xml file for each virtual host with the following setting where the MaxIdleTime is the  maximum idle time allowed, in seconds, before a client is disconnected.

<AutoCloseIdleClients enable=”false”>
<MaxIdleTime>600</MaxIdleTime>
</AutoCloseIdleClients>

It turns out that there is a hidden configuration that sets the amount of time that the server waits to check the configuration. The value is in seconds, and 60 is the default. Together these two numbers represent the amount of time before an idle user is disconnected.

<AutoCloseIdleClients enable=”true”
<CheckInterval>60</CheckInterval
<MaxIdleTime>600</MaxIdleTime>
</AutoCloseIdleClients>

Example:|
As an example assume that you have a number of remote locations with 500 kbps of available bandwidth and you want to make sure that no more than 500 kbps of content are served across that connection at any time. By setting up virtual hosts for each remote location you can set a MaxConnections limit for each virtual host that would limit the number of people that could watch video from that location at any given time. The next step is to make sure that you encode your content to fit with in that limit. This is not the article to talk about encoding but for the purpose of clarity, I would follow the following guideline.  Make sure that you use constant bitrate encoding (CBR) not variable bitrate encoding (VBR) and make sure that the total bitrate is less than the available bandwidth (500 kbps). As an example if I had 500 kbps I might encode my video at 350 kbps and my audio at 90 kbps and that would give me a total of 440 kbps.

Finishing the Configuration:

Now that the virtual host is setup and the content is encoded lets add an entry to each vhost.xml file so that they can have access to the same content. I should point out again that you could simply have copies of content in each virtual host application directory specified by the <AppsDir> setting but if the content is that same that is needlessly using drive space. A better approach would be to have a single directory of content that is shared between virtual hosts. You can do this with a setting in each vhost.xml file called <Streams> in side the <VirtualDirectory> tag. I used the following setting that tells each virtual host with this setting in the vhost.xml file to look in the C:\vhostContent directory for content.

<Streams>/;C:\myvhostContent</Streams>

With this setting there is no need for subfolders you can simply put your video files in the myvhostContent directory.

This setting can be used to group virtual hosts. Remember that the process of limiting bandwidth is based on two criteria. First limiting the number of connections using MaxConnections in the vhost.xml file. Second encoding your content to a specific bitrate that does not over run your available bandwidth. In the example in this article I used 500 kbps of available bandwidth and encoded the content to a total of 440 kbps. If you had groups of remote locations that were similar, for instance lets say that you had four locations that had t1 (1.54Mbps) connections and four locations that had with OC3 (155 Mbps) connections depending on the available bandwidth for each group you would want two sets of content. In this scenario you would have eight virtual hosts. You would edit the vhost.xml file for each virtual host and point it at a one of two content directories using the <Streams> setting mentioned earlier. In this way you would only have two copies of the content but they would be encoded at different bitrates.  For the t1 connections I might encode my content to be under 300 kbps and for the OC3 connection I might encode my content to be 900 kbps or even use Dynamic Streaming to get the most out of the content and connection.

Playing the Content:
So now that we have everything setup how do you play the content. Just to keep things simple lets use Flash CS5. Make sure that you have the newest Flvplayback (version 2.5) component, you can download it from here.  Create a new file (file > new > actionscript 3) then drag the FlvPlayback 2.5 component out onto the stage (save the file). In the property inspector open the source property and enter the protocol (rtmp://) then the name of the folder that represents the name of the vhost (www.first.com) then the application name.  The application name is the name of a folder inside the application directory. Remember that the application directoryis what we specified in the AppsDir setting of the vhost.xml file.

<AppsDir>C:\myvhostApplications\first</AppsDir>

If we consider the preceding setting in the vhost.xml file the application name would be a folder inside the folder with the name first. Lets refer to the application name as simpleAppand lets assume that the video we are going to play is myvideo.flv. That would mean that the source property for the FlvPlayback component would be:

rtmp://www.first.com/simpleApp/myvideo.flv

Summary:
Lets review what we have done. First we created a folder (www.first.com) that represents a virtual host in the conf\_defaultRoot_ directory of the Flash Media Server installation directory. This name is mapped to the machine IP adddress with a DNS entry for production or a hosts file for a development environment. We copied the vhost.xml and application.xml file into that folder (www.first.com) from the conf\_defaultRoot_\_defaultVHost_ folder of the FMS installation folder. We added an entry to the <AppsDir> setting in the vhost.xml file as well as the <MaxConnections>- setting. The <AppsDir> sets up an application directory for the virtual host and the MaxConnections setting limits the number of connections coming into that specific virtual host. Then you encoded your content to fit within the bandwidth limits required for that virtual host and finally we added an entry to the <Streams> so that groups of virtual hosts could have access to the same content without having to copy the same content into every virtual host application directory. Finally you will have to create different Flash / Flex applications or pass in variables so that each location uses the correct connection string (rtmp://{virtualhost}/{application}.{video}). Check out an article that I wrote regarding how to pass variables into Flash using the query string.

CS5 Magic

If you have not heard or you have nothing to do with content creation on the web you can disregard this post. On the other hand if you have anything to do with content creation on the web no matter if you are a designer or a developer you are going to want to pay attention to this release.

Securing Flash Media Interactive Edition

A critical component to rich media is securing your content and resources. In this article I am going to cover how to restrict someone with the Flash Media Live Encoder or for that matter any encoder from publishing to the Flash Media Interactive Server. In the process I am going to show you how to allow someone with the appropriate permissions and the Flash Media Live Encoder to publish to the server.

There are many ways to accomplish this goal. First there are Adobe partners that have written plugins for the Flash Media Server that allow you to restrict access to the server through the use of these plugins.

There are also server side APIs that allow you to connect with other systems and data. For instance you can use the WebService class to create and access a WSDL/SOAP web service or the XML class lets you load, parse, send, build, and manipulate XML.

In this short example I am going to use a server side event “onPublish” to retrieve the querystring and respond to a request to publish a live stream from the Flash Media Live Encoder to the Flash Media Interactive Server. Now there is a reason that I am calling out the Flash Media Interactive Edition and not the Streaming Edition and that is that the Streaming Edition does not support server side scripting.

Server side scripts are written and stored in “.asc” files in an application directory inside the application folder on your Flash Media Server. As an example if I had a application called foo I would store my server side script (e.g. main.asc)  in the following location.

server side script location

There are a number of events that you can work with on the server side; for instance onAppStart, onConnect, onPublish. You can find information about these and other events, methods and properties in the documentation.

Lets take a look at the final server side script in the main.asc file.

application.onAppStart=function(){
trace(“***** on App Start”);
}

application.onConnect=function(clientObj){
trace(“**** on connect”);
this.acceptConnection(clientObj);
return true;
}

application.onPublish = function(clientObj, streamObj){
logon = extractQueryString(streamObj.publishQueryString, “logon“);
if(logon != “fmle”){
application.disconnect(clientObj);
trace(“Sorry you aint publishing”);
}

}
function extractQueryString(queryString, arg){
var returnValue = “”;
temp = arg + “=”;
i = queryString.indexOf(temp);
if (i != 0){
temp = “&” + arg + “=”;
i = queryString.indexOf(temp);
}
if (i != -1){
returnValue = queryString.substr(i+temp.length);
i = returnValue.indexOf(“&”);
returnValue = returnValue.substr(0, i);
}
return returnValue;
}

In the preceding code the events are in bold. The helper function that will extract the search term (i.e. the second parameter that we pass in to the extractQueryString function called arg)  that we tell it from the querystring is green. The bit that disconnects an in appropriate publisher is red.

First let me say that this is a very simple example that should be coupled with functionality that does more to integrate with existing systems (e.g. ldap) but after many calls from customers concerned that someone might be able to publish inappropriate content or use their bandwidth I thought I would at least get the ball rolling. The part of the script in red is a great place to look at integrating with other systems. Notice that in the if statement that I am simply looking for the string “fmle” this should really be a more robust solution but it will work for this simple example.

In the preceding code onAppStart does just that it fires when the application starts. The onConnect fires when a client connects to this application. Finally onPublish fires when someone tries to publish a stream to the server.

There are two parameters the first is the client object that represents the client publishing the stream to the server. The second is a reference to the stream that the client is attempting to publish. Even though I am not going to cover it in this article it is worth mentioning that you can use the stream reference to publish a stream from one server to another in the event that you want to propagate a stream across a number of servers.

What will happen when someone tries to publish a stream to an application that has this “main.asc” in the application folder? If they do not add “logon=fmle” to the connection they will be disconnected (see script in red above).  Most people do not want to stop all Flash Media Live Encoders from publishing to their server they just want to make sure that the right users can publish to their server. In this example the way that we do that is to make sure that who ever attempts to publish to the server includes “fmle” in the querystring. This has to happen from the Flash Media Live Encoder or for that matter any encoder that you are using to publish to the server. In this example I am going to use the Flash Media Live Encoder.  The following is a screen shot of the Flash Media Live Encoder’s output panel:

Flash Media Live Encoder Output Panel
Flash Media Live Encoder Output Panel

Substitute your server dns name or ip address for localhost in the preceding screenshot. There are two elements that you need to be aware of in the preceding. First notice that “foo” is after the last forward slash “foo” represents the  application name which is the same as the name of the directory where “main.asc” is located (see first screenshot). Second notice that after the stream name there is the following “?logon=fmle” this is the querystring. This querystring is initially extracted by using publishQueryString property of the stream object (see blue script above). This represents the entire querystring which often includes other parameters. Since we are only interested in the “logon” parameter we pass the querystring to extractQueryString(see green script above). This function parses the query string and returns the term and value of the term we pass into the extractQueryString function (the term that we are passing in is logon and is the second argument in the following script:

logon = extractQueryString(streamObj.publishQueryString, “logon“);

The value of this argument will have to be “fmle” or the attempt to publish will be denied.

That should cover it. If you have questions or comments let me know. I will most likely follow this up with short article about swf verification.

A Mystery Unfurls

Every now and then I will find a website or content example that lives up to my belief that the web has so much more potential than the majority of the content available today. I am constantly looking for that amazing “lean forward” experience that draws you in and makes you want to reach out to the other people interacting with the content to see if their experience even remotely matches your own. Good news, I have found it and it is called “CIRCLE OF EIGHT”. It is a multi-episode supernatural thriller that combines social media, gaming and a great plot line. The quality of this production is fantastic. Could this be a block buster series that finds all or most of its potential on the web? I think that it could be but only time will tell.