FLV Checker

Some of you maybe familiar with the FLVCheck tool that allows you to check to see if a Flash video is properly formatted. If you are you would also know that it is a command prompt application (i.e. there is no user interface). To get familiar with the ability to use native process support in Adobe AIR I wrapped the FLVCheck tool in a simple Flex application. This is a simple UI that allows you to drag and drop and flv file onto the application so that it can check the format and fix simple issues. This application does not add any functionality to that application all it does is add a user interface. The application is free but I do ask that you register in order to download. You will also find the Adobe Connect custom video pod at the same location after you are registered. If the registration form does not load, clear your browser cache and try again.

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.