Offer the best viewing experience
The player shown above uses dynamic stream switching with Amazon CloudFront. Here is a tutorial about configuring Amazon CloudFront streaming using Flowplayer.
People with fast connections are served with HD content; people with slow connections are served with smaller files (i.e. lower bitrate). Playback needs to be uninterrupted while maintaining the best possible video quality. Video files are encoded with several different bitrates so that good matches are available for the connection speeds that are being targeted.
Quality Of Service monitoring makes sure that playback continues
uninterrupted using the best possible quality. The plugin continuously
monitors and calculates the following metrics: available maximum bandwidth,
number of dropped video frames, the amount of data currently buffered and
the available video screen size. Based on these factors, it determines the
optimal bitrate. If needed the stream is dynamically switched during playback
(requires Wowza 2.2.4 and above or Adobe Flash Media Server 3). Continuous monitoring and control is required
to ensure good results as the available bandwidth fluctuates.
The player dimensions are considered when selecting the appropriate file. The plugin never selects a file that has dimensions larger than the player's screen. Selecting too large a file would waste bandwidth. When going fullscreen, the player switches to a larger file if available bandwidth permits.
Recommendations For Dynamic Stream Switching
Flash Media Server and Wowza Media Server require consistant encoding specifications to obtain smooth video switching. It is recommended a keyframe interval of 5 seconds to make smooth switching fast, and required to be the same for all multi-rate videos. The same audio samplerate and frame size is also recommended for smooth switching.
More Information:
Features
- Quality Of Service monitoring and dynamic stream switching.
- Support for progressive download, pseudostreaming (except for php-pseudostreaming), and RTMP.
- Manual selection of the bitrate. Users can be offered the option to select their preferred bitrate.
Flowplayer configuration
Here is the configuration for this demo. Check the commented code. The
bitrates array is used to specify the video files corresponding to the
different bitrates. The bwcheck plugin is simple to configure. Use the
dynamic property to enable dynamic switching and quality of service
monitoring.
flowplayer("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.11.swf", {
clip: {
urlResolvers: 'bwcheck',
provider: 'rtmp',
autoPlay: false,
scaling: 'fit',
// available bitrates and the corresponding files. We specify also the video width
// here, so that the player does not use a too large file. It switches to a
// file/stream with larger dimensions when going fullscreen if the available bandwidth permits.
bitrates: [
{
url: "mp4:bbb-800", width: 480, bitrate: 800,
// this is the default bitrate, the playback kicks off with this and after that
// Quality Of Service monitoring adjusts to the most appropriate bitrate
isDefault: true
},
{ url: "mp4:bbb-1200", width: 720, bitrate: 1200 },
{ url: "mp4:bbb-1600", width: 1080, bitrate: 1600 }
]
},
plugins: {
// bandwidth check plugin
bwcheck: {
url: "flowplayer.bwcheck-3.2.10.swf",
// CloudFront uses Adobe FMS servers
serverType: 'fms',
// we use dynamic switching, the appropriate bitrate is switched on the fly
dynamic: true,
netConnectionUrl: 'rtmp://s3b78u0kbtx79q.cloudfront.net/cfx/st',
// show the selected file in the content box. This is not used in real installations.
onStreamSwitchBegin: function (newItem, currentItem) {
$f().getPlugin('content').setHtml("Will switch to: " + newItem.streamName +
" from " + currentItem.streamName);
},
onStreamSwitch: function (newItem) {
$f().getPlugin('content').setHtml("Switched to: " + newItem.streamName);
}
},
// RTMP streaming plugin
rtmp: {
url: "http://releases.flowplayer.org/swf/flowplayer.rtmp-3.2.10.swf",
netConnectionUrl: 'rtmp://s3b78u0kbtx79q.cloudfront.net/cfx/st'
},
// a content box so that we can see the selected video dimensions. This is not used in real
// installations.
content: {
url: "http://releases.flowplayer.org/swf/flowplayer.content-3.2.8.swf",
top: 0, left: 0, width: 250, height: 150,
backgroundColor: 'transparent', backgroundGradient: 'none', border: 0,
textDecoration: 'outline',
style: {
body: {
fontSize: 14,
fontFamily: 'Arial',
textAlign: 'center',
color: '#ffffff'
}
}
}
}
});
Additional demo and alternative plugin
Configuration
Bitrate items
The available bitrates and their properties are defined in the clip object. Here is an example of
this bitrate list and the bitrate items contained in it.
clip: {
bitrates: [
{ url: "mp4:bbb-800", width: 480, bitrate: 800, isDefault: true },
{ url: "mp4:bbb-1200", width: 720, bitrate: 1200 },
{ url: "mp4:bbb-1600", width: 1080, bitrate: 1600 }
]
}
The properties of the bitrate items are as follows:
| property / datatype | Description |
|---|---|
|
|
The url to the clip. |
|
|
The clip bitrate. |
|
|
The width of the video encoded in this bitrate. |
|
|
Set the clip as default to play on startup, will be used as fallback if there was no bandwidth detected. |
Plugin configuration options
| property / datatype | Default | Description |
|---|---|---|
|
|
|
Used when detected bandwidth values are remembered (see the rememberBitrate setting). This is the name of the Shared Object where the bitrates are saved. You might want to change this if you have different sets of files and you want to keep the detected bandwidths separate for those sets. |
|
|
|
Used when detected bandwidth values are remembered (see the rememberBitrate setting). The expiration time for cached bitrates. The default value is 24 hours (86400 seconds). After the expiration period has passed, the bandwidth is re-detected. |
|
|
|
Set this to |
|
|
|
Enables dynamic stream switching (Quality Of Service monitoring) for Adobe Flash Media Server 3 and Wowza Media Server 2. |
|
|
|
When enabled, this feature will dynamically calculate the best buffer time to suit the available bandwidth. |
|
|
|
Set this to |
|
|
|
Sets the maximum video width that will be selected. By default the maximum width is the width of the video screen area. This value can be used to override this. Sometimes used when the player is resized dynamically using scripting to follow the selected stream dimensions. |
|
|
|
The URL used to check the bandwidth. For HTTP-based checking, this should point to a reference file that is loaded as part of the check. The file should reside on the same host as the plugin, or it will require domain context policies for remote loading of the file to prevent sandbox issues. For RTMP this should be a RTMP url pointing to a streaming server. |
|
|
|
Specifies the dynamic switching rules to be used. Used when
|
|
|
|
Indicates whether the detected bandwidth should be remembered for the
client browser. If |
|
|
|
Identifies the type of server that we will be checking against. Available values are 'http', 'red5', 'wowza', and 'fms'. |
|
|
|
Used when |
RSS files
You can specify the available bitrates and files in a RSS playlist file. See this demo with a RSS file used to specify the bitrates for more information.
JavaScript API
Methods
| Method | Returns | Description |
|---|---|---|
|
|
|
Gets the current bitrate. The returned value is the bitrate in use after the latest bitrate transition has been completed. If a bitrate switch is in progress the value reflects the bitrate right now being used, not the one we are switching to. |
|
|
|
Changes the stream to the specified bitrate. The specified value should
be one of the values contained in the |
|
|
|
Enables or disables dynamic stream switching. The specified |
|
|
|
Initiates a new bandwidth check. The detected bandwidth is stored in
the client browser if the config option |
Events
| Event | When does it fire? |
|---|---|
|
|
Fires when the bandwidth has been detected. The callback is fed with the following arguments:
|
|
|
Fires when a bitrate switch is initiated. A second event is fired when
the switch is completed, see below. This event is called only when the
|
|
|
Fires when the bitrate switch has been completed. Once fired the new
stream starts playing and is shown in the player. This event is called
only when the
|
|
|
Fires when the server has returned a failure to dynamically switch the video. This is generally due to keyframe inconsistancies between the multi-rate videos which is required by the servers. As fallback the bwcheck plugin will attempt a native switch of the video by reloading the video.
|
Here are the events related to establishing a connection and clustering. Note
that if you are not clustering the hosts used for bandwidth checking, the
host index will always have a value of zero.
| Event | When does it fire? |
|---|---|
|
|
Fires when the plugin starts a new connection attempt. The callback is fed with two arguments:
|
|
|
Fires when a connection attempt has failed. The callback is fed with two arguments:
|
|
|
Fires when all hosts in the cluster have failed. See also the connectCount option, that specifies how many times the hosts are evaluated before failing. |
Advanced features
Clustering of bandwidth checks
You can configure an array of hosts to be used for the bandwidth check. The plugin chooses a live host from this array until it finds one that does not fail. This provides a way to add failover. Note that this is not designed to be used with dynamic stream switching as the hosts in the cluster are used only in the initial RTMP bandwidth check call. Here is an example of how to configure clustering for the bandwidth check:
bwcheck: {
url: "flowplayer.bwcheck-3.2.10.swf",
serverType: 'red5',
// the actual streaming happens from this host. In reality you would
// probably configure a cluster of hosts here too.
netConnectionUrl: 'rtmp://electroteque.org/bwcheck',
// the hosts used for the initial bandwidth check
hosts: [
{host:'rtmp://electroteque1.org/bwcheck'},
{host:'rtmp://electroteque2.org/bwcheck'},
{host:'rtmp://electroteque.org/bwcheck'}
]
}
The configuration above is for clustering the bandwidth checking connections only. If you want to cluster your streaming connections, then you need to use our clustering plugin.
The clustering configuration for bandwidth checking and for the actual streaming are separate. This is because in many cases the RTMP applications used for bandwidth checking are different from the applications that are used for streaming, and therefore their host URLs are also different.
Download
| flowplayer.bwcheck-3.2.10.swf | just the working flash file to get you going |
| flowplayer.bwcheck-3.2.10.zip | working flash file (swf) + README.txt and LICENSE.txt |
| flowplayer.bwcheck-3.2.10-src.zip | source code |
Please right-click and choose "Save link as..." (or similar)
See the version history for this tool.
Found a bug?
If you encounter problems in this script, please send a bug report to the bug reporting forum. If you have a problematic page, including a direct URL to that page is by far the most effective way of helping us to find a bug.