18 April 2011
You should be generally familiar with principles of streaming video on the web and encoding video for Flash.
Intermediate
Adobe HTTP Dynamic Streaming was developed by Adobe to deliver content to users via HTTP, enabling dynamic switching of video content quality depending on the bandwidth available to the user. It is especially effective when it works together with Adobe Flash Accesss 2.0 to protect valuable assets. This guide gives you step-by-step instructions to get your Flash media video platform up and running.
Here are the main features of HTTP Dynamic Streaming content delivery when used with Flash Access 2.0:
These features meet the requirements of most major video content rightsholders, thus enabling you to maintain a broad choice of content at your online resources.
The solution to protect the content and distribute it using Flash Access is intended for the protection of content in multimedia projects using HTTP Dynamic Streaming technology (see Figure 1).
The solution consist of four main modules (content stages):
Content preparation (File Packager for video on demand)
Content preparation includes encoding and encryption using the File Packager tool, which supports the FLV (VP6/MP3) and F4V (H.264/AAC) file formats.
The policies applied at content playback can be managed by the license server, so you can apply the simplest (anonymous) policy of content encryption for HTTP Dynamic Streaming.
For a detailed description, please refer to the section "Content preparation" in this tutorial.
Content delivery (HTTP delivery)
The content encryption process creates three types of files:
For caching the video fragments, a CDN or Nginx server can be used.
License server
Adobe Flash Access Server for Protected Streaming is a license server issuing licenses to users and managing content delivery policies. For a detailed description, please refer to the section, "Configuring the Flash Access Server for Protected Streaming".
Playback
To play back the test content, you can use the freely available OSMF player. You'll find a detailed description in the section, "OSMF video player".
To get things working (see the complete picture in Figure 1), you will have to use some additional tools and modules, as follows.
File Packager (f4fpackager) is an Adobe console application that does the following:
For a detailed description, please refer to the section, "Content preparation".
For video content encoding, a symmetric block encryption algorithm (Advanced Encryption Standard) is used with a block size of 128 bits and a 128-bit key. This is an encryption standard providing high storage security and content delivery in CDNs.
HTTP Origin Module for Apache handles requests for content fragments. It is included in all versions of Flash Media Server 4, or it can be downloaded from the Adobe website.
A detailed description of content delivery process is given in the section, "HTTP Origin Module operation."
Open Source Media Framework is a reliable and flexible ActionScript framework for rapid development of SWF-based video players. The OSMF sample player (see Figure 2) is designed for HTTP Dynamic Streaming. A detailed description of the player is given in the section, "OSMF video player".
To prepare content for HTTP streaming, you need to use the File Packager, which provides the following:
To enable content fragmentation in Windows:
f4fpackager - input-file = sample.f4v - output-path = c: \ sampleoutput
After the encoding is complete, you get the following files: sampleSeg1.f4f, sample.f4x, and sample.f4m.
To enable content fragmentation in Linux:
f4fpackager - input-file = sample.f4v - output-path = / sampleoutput
After encoding, you get the following files: sampleSeg1.f4f, sample.f4x, and sample.f4m.
This includes encoding of content at several bit rates: for example, 150 kbps, 700 kbps, and 1500 kbps. In this example, three files are encoded at different bitrates: sample1_150kbps.f4v, sample1_700kbps.f4v, and sample1_1500kbps.f4v. In Flash Media Server, these files are located in the directory rootinstall\applications\vod\media.
f4fpackager - input-file = sample1_150kbps.f4v - bitrate = 150
After the encoding is complete, you get the following files: sample1_150kbpsSeg1.f4f, sample1_150kbps.f4x, and sample1_150kbps.f4m.
f4fpackager - input-file = sample1_700kbps.f4v - manifest-file = sample1_150kbps.f4m - bitrate = 700
After the encoding is complete, you get the following files: sample1_700kbpsSeg1.f4f, sample1_700kbps.f4x, and sample1_700kbps.f4m.
In addition to details on the current encoding (sample1_700kbps.f4m), the manifest file sample1_700kbps.f4m also contains information about the first encoding (sample1_150kbps.f4m).
After the encoding is complete, you get the following files: sample1_1500kbpsSeg1.f4f, sample1_1500kbps.f4x and sample1_1500kbps.f4m.
In addition to details on the current encoding, the manifest file sample1_1500kbps.f4m contains information about the first encoding (sample1_150kbps.f4m) and the second encoding (sample1_700kbps.f4m). If you encode with multiple bit rates, the information from the first manifest file is copied to the second manifest file, from the second to the third, and so on.
The latest manifest file includes the most up-to-date information on all three files encoded and their different bit rates.
File Packager is designed not only to encode but also to encrypt content. Setting a large number of parameters is much easier using a configuration file:
#offline
<input-file> someFile.f4v </ input-file>
<content-id> contentId </ content-id>
<common-key> commonKey.bin </ common-key>
<license-server-url> http://server1.com:9999 </ license-server-url>
<license-server-cert> licenseServer.der </ license-server-cert>
<transport-cert> transportCert.der </ transport-cert>
<packager-credential> packagerCredential.pfx </ packager-credential>
<credential-pwd> mYpwd </ credential-pwd>
<policy-file> policyFile.pol </ policy-file>
#offline
f4fpackager - conf-file = f4fpackager_config.xml
Here's a description of the parameters:
input-file is the path to the source video file.content-id is a content identifier you select. It's used with the common-key parameter to generate the content encryption key. Keep the same content-id and common-key settings for an entire set of content to make sure that users can decrypt your content set with a single license.common-key is a unique 128-bit key (created by the OpenSSL utility) that's used with the content-id to create the encryption key.license-server-url is a URL of the Flash Access for Protected Streaming license server. It grants the user license.license-server-cert is an encoded license server certificate. It is obtained from Adobe as a result of licensing and never changes.transport-cert is an encoded transport certificate (.der). It is obtained from Adobe as a result of licensing and never changes.packager-credential is a mandate for encryption of content (. pfx). It is obtained from Adobe as a result of licensing and never changes.credential-pwd is a password. It is obtained from Adobe as a result of licensing and never changes.policy-file is a policy (. pol). The policy file can be created using the java API or a utility that comes with Flash Access (AdobePolicyManager.jar).All parameters should contain relative or absolute file paths for the files. For more information on File Packager, see these resources:
The manifest file (F4M) includes the following:
Here is an example of the manifest file for content playback:
<?xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns="http://ns.adobe.com/f4m/1.0">
<id> myvideo </ id>
<duration> 253 </ duration>
<mimeType> video / x-flv </ mimeType>
<streamType> recorded </ streamType>
<baseURL> http://example.com "</ baseURL>
<drmMetadata url="http://mydrmserver.com/mydrmmetadata"/>
<bootstrapInfo profile="named" url="/mybootstrapinfo"/>
<media url="/myvideo/medium" bitrate="908" width="800" height="600"/>
</ Manifest>
Here is an example of the manifest file for multi-bitrate content playback:
<?xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns="http://ns.adobe.com/f4m/1.0">
<id> myvideo </ id>
<duration> 253 </ duration>
<mimeType> video / x-flv </ mimeType>
<streamType> recorded </ streamType>
<baseURL> http://example.com "</ baseURL>
<drmMetadata url="http://mydrmserver.com/mydrmmetadata"/>
<bootstrapInfo profile="named" url="/mybootstrapinfo"/>
<media url="/myvideo/low" bitrate="408" width="640" height="480"/>
<media url="/myvideo/medium" bitrate="908" width="800" height="600"/>
<media url="/myvideo/high" bitrate="1708" width="1920" height="1080"/>
</ Manifest>
The content file (F4F) contains fragments of the encrypted content. You'll find more information about F4F files in the white paper, HTTP Dynamic Streaming on the Adobe Flash Platform (PDF).
When your video library is ready to be delivered through HTTP Dynamic Streaming, you are ready to configure your server's HTTP infrastructure. Content delivery is enabled by two main modules:
HTTP provides a variety of popular tools for load balancing, caching, and efficient content delivery that are applicable to standard web content.
Table 1 compares various content delivery methods and their parameters, delineating the benefits of HTTP Dynamic Streaming.
Table 1. Comparing content delivery methods
| RTMP Dynamic Streaming | HTTP progressive download | HTTP Dynamic Streaming | |
| Flash Player version | Flash Player 6 or later | Flash Player 7 or later | Flash Player 10.1 or later |
| Quality of service | Measured on bandwidth and performance | N/A (often resulting in poor user experience) | Measured on bandwidth and performance |
| Adaptive bit rate | Yes | No | Yes |
| Publishing workflow | Simple | Simple | Packaging plus manifest file required |
| Content protection | Real time (RTMPe), SWF verification, DRM | DRM for VOD only | DRM for both live and VOD |
| Live support | Yes | No | Yes |
| Live latency | Less than 1 sec. * | N/A | Less than 30 sec. ** |
| Synchronous communication | Yes | No | N/A |
| Logging | Server side | No | Client side |
| Cacheable | No | Yes | Yes |
* Live latency for RTMP may vary depending on network infrastructure and buffer settings.
** Live latency for HTTP Dynamic Streaming may vary depending on encoding, fragmentation, and buffer settings.
One of the most impressive benefits of HTTP Dynamic Streaming is that a user with a very slow Internet connection can pause the playback and wait until the video content is fully downloaded. This way, even users with a narrowband Internet connection can watch high-quality videos without interruption.
You'll find more information about the characteristics of HTTP Dynamic Streaming in the Adobe white paper, HTTP Dynamic Streaming on the Adobe Flash Platform (PDF).
To play back content in an OSMF player, you should specify the URL of the manifest file (F4M). Here is how it works:
The fragmented structure of the content (F4F) is shown in Figure 3.
As the content is delivered to the user via HTTP, the delivery process can be analyzed using Firefox with the FireBug plugin installed (see Figure 4).
To create an HTTP Dynamic Streaming application, do the following:
Setting up the Flash Media Interactive Server 4 for HTTP Dynamic Streaming is described in the white paper, HTTP Dynamic Streaming on the Adobe Flash Platform (PDF). For more general information on FMS setup and configuration, see the Flash Media Server 4.0 Help.
Note: If the webroot directory already has the "images" directory, copy the files from the OSMF player's \images directory to webroot\images.
For more details, see the section, "OSMF video player".
Note: The OSMF player requires Flash Player 10.1 or later.
For multi-bitrate streaming, press Q. Press Q– and Q+ to change the content playback bitrate.
To manage digital rights and user access to protected content, Adobe provides Flash Access Server for Protected Streaming. This server issues user licenses to protected content.
Because the policies applied on content playback can be customized by the license server, you can encrypt the content by the simplest (anonymous) policy of content protection.
Flash Access Server for Protected Streaming ignores the policy in the encrypted file itself. Instead, content access parameters and limitations need to be defined on the server side in these configuration files:
In the owner's global configuration file, you can specify a full path to flashaccess-tenant.xml or a path relative to the tenant's directory (LicenseServer.ConfigRoot/flashaccessserver/tenants/tenantname).
Tenant's configuration file:
The tenant's configuration file, flashaccess-tenant.xml, provides settings that control access to the tenant's content:
Note: All licenses issued by Flash Access Server for Protected Streaming are valid for no more than 24 hours (86,400 seconds).
Global configuration file:
The most important settings, such as caching and logging, are configured in the global configuration file, flashaccess-global.xml:
<Caching>: cache management parameters; for example,<Caching refreshDelaySeconds ="..." numTenants ="..."/>
refreshDelaySeconds determines update frequency. Small interval can affect server performance.
numTenants is number of tenants of the server.
<Logging>: specifies the logging level; for example,<Logging level ="..." rollingFrequency =""/>
level determines the level of logging. If it is set to "DEBUG", it saves quite a lot of messages to the log file. For optimum performance, Adobe recommends setting the value to "WARN". However, there is a risk of losing important information, such as licensing audit data. For minimal logging, set the value to "INFO".
rollingFrequency specifies how frequently the log files are changed. You can set the value to " MINUTELY ", " HOURLY ", "TWICE- DAILY ", " DAILY ", " WEEKLY ", " MONTHLY ", or " NEVER ".
With Flash Access Server for Protected Streaming, a specific policy is used when playing back the content (the parameters are set in the Flash Access configuration files by default):
Log files are created by Flash Access Server for Protected Streaming and are located in a directory defined as LicenseServer.LogRoot.
Note: If the current log file is deleted or moved on server startup, the server will not create a new log file and the data might be lost in the future.
Directory structure:
LicenseServer.LogRoot/
flashaccess-global.log
flashaccessserver/
flashaccess-partition.log
tenants/
tenantname/
flashaccess-tenant.log
The global log file flashaccess-global.log is located in a directory defined as LicenseServer.LogRoot. This log file contains messages from the Flash Access SDK and messages generated by the server initialization.
The flashaccess-partition.log configuration file is located in the LicenseServer.LogRoot/flashaccesserver directory. This log file includes messages on requested licenses.
The configuration file flashaccess-tenant.log islocated in LicenseServer.LogRoot/flashaccesserver/tenants/tenantname.
This log file includes information on each requested license.
Using a custom authentication mechanism implies inserting a special token (AuthenticationToken) into the license request:
To enable custom authentication in Flash Access Server for Protected Streaming, you should:
Custom authentication type. Such policies can be created with the Flash Access SDK.SampleAuthorizer .<AuthExtensions>
<Extension className="com.adobe.flashaccess.server.license.extension.auth.SampleAuthorizer"/>
</AuthExtensions>
For more information, see the white paper, Protecting Content (PDF).
To implement a custom authentication class, follow these steps:
com.adobe.flashaccess.server.license.extension.auth (see Figure 5).
package com.adobe.flashaccess.server.license.extension.auth;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import org.apache.commons.logging.Log;
public class SampleAuthorizer implements IAuthorizer {
public SampleAuthorizer() {}
public void authorize(IMessageFacade message, IAuthRequestFacade request,
IAuthResponseFacade response, IAuthChain chain, Log log) throws Exception {
if(message.getAuthToken() != null){
System.out.println(new String(message.getAuthToken()));
URLConnection conn = null;
DataInputStream dis = null;
boolean authValid = false;
try {
conn = new URL("http://localhost/auth.jsp?" +
new String(message.getAuthToken())).openConnection();
conn.setDoOutput(true);
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
dis = new DataInputStream(conn.getInputStream());
String inputLine = null;
while ((inputLine = dis.readLine()) != null)
if(inputLine.equalsIgnoreCase("auth=true")){authValid = true; k;}
} catch (IOException e) {
} finally{
if(dis != null) dis.close();
}
if(authValid){
chain.execute(message);
return;
}
}
throw new Exception("AuthToken error");
}
@Override
public IAuthorizer clone() {
return new SampleAuthorizer();
}
}
To play the video content in your application, you should create a Flash Access compliant video player for secure content playback based on OSMF 1.5 (see Figure 6). The source code for the player is given in this article.
During initialization of the video player, create a new instance of the MediaPlayerSprite class. For its mediaPlayer property, set the DRMEvent.DRM_STATE_CHANGE event handler. This means that on DRMEvent , the onDRMStateChangeHandler method is called to analyze the event:
private function initMediaPlayer (): void
{
_mediaPlayerSprite = new MediaPlayerSprite ();
_mediaPlayerSprite.mediaPlayer.addEventListener (DRMEvent.DRM_STATE_CHANGE,
onDRMStateChangeHandler)
addChild (_mediaPlayerSprite);
}
The addMedia method is used to add a new stream to play. This method creates an instance of the URLResource class, and the content URL (for example, http://server_url/content.f4m) is passed to the class constructor. Next, create a new MediaFactory object and an instance of the F4MElement class whose constructor accepts your URLResource, and an instance of the F4MLoader class whose constructor receives the MediaFactory object:
private function addMedia (m_url: String): void
{
var _urlResource: URLResource = new URLResource (m_url);
var _factory: MediaFactory = new MediaFactory ();
var _f4mElement: F4MElement = new F4MElement (_urlResource, new
F4MLoader (_factory));
_mediaPlayerSprite.mediaPlayer.media = _f4mElement;
}
The onDRMStateChangeHandler method is invoked whenever a DRMEvent is raised by the mediaPlayer property of the MediaPlayerSprite class. This method loops through all the events of this type and initiates certain actions when it finds a match. For example, when the RMState.AUTHENTICATION_NEEDED event is raised, this indicates that authentication is required. In this case, authentication is performed as follows:
_mediaPlayerSprite.mediaPlayer.authenticate ("test", "test")
where test is a username and password, respectively.
It should be noted that the authentication function can be implemented so that the username and password play an entirely different role (for example, as web session identifiers):
protected function onDRMStateChangeHandler (evt: DRMEvent): void
{
switch (evt.drmState) {
case DRMState.AUTHENTICATING:
break;
case DRMState.AUTHENTICATION_COMPLETE:
break;
case DRMState.AUTHENTICATION_ERROR:
break;
case DRMState.AUTHENTICATION_NEEDED:
_mediaPlayerSprite.mediaPlayer.authenticate ("test", "test");
break;
case DRMState.DRM_SYSTEM_UPDATING:
break;
case DRMState.UNINITIALIZED:
break;
}
}
By using these methods, you can play back DRM content in SWF-based video players.
If you need to pass a token for authentication, you should use the new API in the DRMManager class. The method setAuthenticationToken (serverUrl: String , domain: String , token: ByteArray ): void let you pass any token you have.
For more information, see the ActionScript 3.0 Reference documentation for the DRMManager class.
This tutorial has given you an introduction to using Flash Access to protect content served with HTTP Dynamic Streaming, including building a Flash Access compliant OSMF-based media player.
The resources referenced in this tutorial can provide you with more in-depth knowledge and guidance:
Also check out the DENIVIP blog, where we publish useful Flash Platform related content, such as the post, Flash Media Server: URLs tokenization.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.
Tutorials & Samples |