Flash Media Server |
|||
| Developing Media Applications > Working With Media Files > Working with video > Customizing stream delivery | |||
You can use the Flash Media Server custom stream delivery feature to provide the best streaming experience for each client by serving different versions of the same stream to different clients. For example, you can provide video encoded with the Sorenson Spark codec to clients with Flash Player 7 and video encoded with the On2 VP6 codec to clients with Flash Player 8. You can also provide video encoded at different bit rates based on the bandwidth of the client.
Flash Media Server has two features that work together to let you deliver custom streams: virtual directories and virtual keys.
You can create multiple directories on the Flash Media Server and store different versions of the same video content in each directory (for example, a video encoded with different codecs or at different bit rates). Each client that connects to the Flash Media Server is given a virtual key (stored in the server-side Client.virtualKey property). By default, the virtual key is based on the value of the client's Flash Player version. In the vhost.xml configuration file, you can map the keys to the directories in the VirtualKeys and VirtualDirectory sections of the file to deliver custom content for individual clients. For customizing stream delivery based on bandwidth, you must check the client bandwidth in a script and change the client keys accordingly.
You can set the key and directory values directly in the vhost.xml file or you can use server-side ActionScript (the Client.virtualKey property and the Stream.setVirtualPath() method) to set the values. After you've set up the mapping in the vhost.xml file (or programatically), each connecting client is automatically served the appropriate video content.
For more information about the vhost.xml configuration file, see Vhost.xml file in Managing Flash Media Server.
Flash Media Server can encode and deliver On2 V6 and Sorenson Spark encoded video. Flash Player 8 supports both codecs; Flash Player 7 and earlier versions support only the Sorenson Spark codec. You can create virtual directories on the server to store copies of video streams in each format; this lets you deliver the highest quality content to clients with Flash Player 8.
Consider the following example: a user wants to play a stream and has Flash Player 8 installed on their computer. Flash Player 8 is capable of playing On2 video. Flash Media Server requests the HappyStream.flv file. After contacting the server, Flash Player 8 determines the value of the server-side Client.virtualKey property. The virtualKey property maps to the On2 streams directory, instead of to the default streams directory and the HappyStream.flv stream encoded with the On2 codec is played.
To create an automatic stream delivery mechanism based on Flash Player version, edit the vhost.xml file as follows:
<VirtualKeys>
<Key from="WIN 7,0,19,0" to="WIN 9,0,0,0">A</Key>
<Key from="WIN 6,0,0,0" to="WIN 7,0,18,0">B</Key>
<Key from="MAC 6,0,0,0" to="MAC 7,0,55,0">B</Key>
</VirtualKeys>
<VirtualDirectory>
<Streams key="A">foo;c:\streams\on2</Streams>
<Streams key="B">foo;c:\streams\sorenson</Streams>
<Streams key="">foo;c:\streams</Streams>
</VirtualDirectory>
For more information about editing the Key and Streams tags, see Vhost.xml file in Managing Flash Media Server.
To deliver video to a client based on the client's bandwidth, encode the video at different bit rates (and optionally using different codecs) and create directories in which to store the streams, as in the following example:
Within the VirtualKeys tag of the vhost.xml file, set the virtual key for Flash Player 7 and below to fp7 and set the virtual key for Flash Player 7 (7.0.19.0) and later (the player version that supports the On2 codec) to fp8, as in the following example:
<VirtualKeys>
<Key from="WIN 8,0,0,0" to="WIN 9,0,0,0">fp8</Key>
<Key from="MAC 8,0,0,0" to="MAC 9,0,0,0">fp8</Key>
<Key from="WIN 6,0,0,0" to="WIN 7,0,55,0">fp7</Key>
<Key from="MAC 6,0,0,0" to="MAC 7,0,55,0">fp7</Key>
</VirtualKeys>
Configure your virtual directories to look for client keys of "fp7slow", "fp8slow", and so on, as in the following example:
<VirtualDirectory>
<Streams key="fp7slow">foo;c:\streams\Sorenson22k</Streams>
<Streams key="fp7medium">foo;c:\streams\Sorenson150k</Streams>
<Streams key="fp7fast">foo;c:\streams\Sorenson300k</Streams>
<Streams key="fp8slow">foo;c:\streams\Vp622k</Streams>
<Streams key="fp8medium">foo;c:\streams\Vp6150k</Streams>
<Streams key="fp8fast">foo;c:\streams\Vp6300k</Streams>
<Streams key="">foo;c:\streams</Streams>
</VirtualDirectory>
In your server-side script, in the application.onConnect handler, write a bandwidth detection routine and append the range to the value of each client's virtual key, as in the following example:
client.virtualKey += "slow" client.virtualKey += "medium" client.virtualKey += "fast"
Flash Media Server will now serve content to individual clients based on the client's player version and bandwidth.
The mapping between the virtual keys and virtual directories is made in the vhost.xml file. The <VirtualKeys> section from the vhost.xml file maps virtual keys to a range of Flash Player versions, as in the following example:
<VirtualKeys>
<Key from="WIN 7,0,19,0" to="WIN 9,0,0,0"></Key>
<Key from="WIN 6,0,0,0" to="WIN 7,0,18,0"></Key>
<Key from="MAC 6,0,0,0" to="MAC 7,0,55,0"></Key>
</VirtualKeys>
By default there are no values in the Key tags. To implement this feature, you must add the key values, either directly in the vhost.xml file, or with the Stream.setVirtualPath() method. For example, to implement this feature, set the first key to A, and the second two keys to B, as in the following code:
<VirtualKeys>
<Key from="WIN 7,0,19,0" to="WIN 9,0,0,0">A</Key>
<Key from="WIN 6,0,0,0" to="WIN 7,0,18,0">B</Key>
<Key from="MAC 6,0,0,0" to="MAC 7,0,55,0">B</Key>
</VirtualKeys>
The following is an example of what the <VirtualDirectory> section from the vhost.xml file could look like (the key attribute values and Streams tag values are not in the file by default). The virtual keys are mapped to a virtual path and a physical directory, which are separated by a semicolon (for example, foo;c:\streams). To set up several virtual directories for different Flash Player versions, use the same virtual path with different physical directories for each Streams tag, as in the following example:
<VirtualDirectory>
<!-- Specifies virtual directory mapping for recorded streams. -->
<!-- To specify multiple virtual directory mappings for a stream,-->
<!-- add additional <Streams> tags; one for each virtual dir -->
<!-- mapping. Syntax for virtual directories is as follows: -->
<!-- <Streams>foo;c:\data</Streams>. This maps all streams whose -->
<!-- names begin with "foo/" to the physical directory c:\data. -->
<!-- For example, the stream named "foo/bar" would map to the -->
<!-- physical file "c:\data\bar.flv". Similarly, if you had a -->
<!-- stream named "foo/bar/x", then we first try to find a vdir -->
<!-- mapping for "foo/bar". Failing to do so, we then check for -->
<!-- a vdir mapping for "foo". Since there is one, the stream -->
<!-- "foo/bar" corresponds to the file "c:\data\bar\x.flv". -->
<Streams key="A">foo;c:\streams\on2</Streams>
<Streams key="B">foo;c:\streams\sorenson</Streams>
<Streams key="">foo;c:\streams</Streams>
</VirtualDirectory>
For more information about the vhost.xml file, see Vhost.xml file in Managing Flash Media Server.
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/fms/2/docs/00000081.html