Streaming Media Files

Topics

The basic CloudFront distribution serves HTTP content. You might want to also serve streamed media using a streaming protocol. This section describes how to use CloudFront to stream on-demand media files.

With CloudFront, streaming means that the end user is receiving and using (e.g., viewing) the media simultaneously. A streaming server streams the data over a special protocol to a streaming playback client that plays the media as it receives it. When the end user is done viewing the video (for example), the video isn't stored locally on the end user's system.

Streaming differs from HTTP download in that the end user doesn't use the media until it's been fully downloaded to the local system over an HTTP connection. Once the file is downloaded, a media client plays the video (for example). With a download, a copy of the media remains on the end user's system. You can do HTTP downloads using a basic distribution (basic distributions serve only HTTP content).

The remainder of this topic discusses how to do streaming with CloudFront. You must be using the 2009-12-01 API version (or later), and your media files must be publicly accessible. Streaming private media files with a signed URL is not supported.

Streaming Server and Playback Client

CloudFront uses Adobe Flash Media Server 3.5 to stream on-demand content with Adobe's Real-Time Messaging Protocol (RTMP). CloudFront accepts RTMP requests over port 1935 and port 80.

CloudFront supports the following variants of the RTMP protocol:

  • RTMP—Adobe's Real-Time Message Protocol

  • RTMPT—Adobe streaming tunneled over HTTP

  • RTMPE—Adobe encrypted

  • RTMPTE—Adobe encrypted tunneled over HTTP

Which protocol you use is up to you and depends on your own needs. For a basic summary of RTMP and the file formats that Adobe Flash Media Server supports, go to Overview of Streaming with Flash Media Server 3 on the Adobe web site. This includes information about the supported codecs and containers.

There are resources available on the Internet to help you determine the bit rate to use for your Flash files. For an example, go to Flash video (FLV) bitrate calculator on the Adobe web site.

CloudFront supports all the features in Adobe Flash Media Server 3.5 related to dynamic streaming, which is the ability to switch between different quality streams during playback. For more information, go to Dynamic streaming in Flash Media Server 3.5: Part 1 on the Adobe web site.

To serve streamed content, you need to provide your end users with a playback client to play the media files. You can write your own player using Adobe Flash (for more information, go to http://www.adobe.com/products/flashplayer/), or you can use an existing player, such as JW Player (for more information, go to http://www.longtailvideo.com/).

Layout of Buckets and Distributions

To stream content, you need to provide two types of files to your end users: your media files and the playback client. In this topic, we assume that your media files and your custom playback client are stored in different buckets in Amazon S3, and are served to end users through CloudFront. Making the client available to end users through Amazon S3 and CloudFront is optional. You can also refer end users to a client that is stored elsewhere.

If you're using CloudFront to serve both the client and the media files, you need to use two types of distributions: a basic distribution for the client, and a streaming distribution for the media files. Basic distributions serve files over HTTP, whereas streaming distributions stream media files over RTMP (or a variant of RTMP).

The following diagram shows the general layout of your CloudFront streaming setup.

Setup for streaming

Your client bucket holds the client and is the origin server for a regular HTTP distribution. In this example, the distribution's domain name is d1234.cloudfront.net.

Your streaming bucket holds your media files and is the origin server for a streaming distribution. In this example, the distribution's domain name is s5678.cloudfront.net.

Your site serves a cached copy of the client to each end user (through the d1234.cloudfront.net domain). That client then accesses cached copies of your media files (through the s5678.cloudfront.net domain).

Overall Process to Stream Content

The following figure and table describe the process to stream content.

Process for to stream content

Process for Streaming Content

1

Choose and configure a client to play your media files. For help, refer to the client's documentation.

2

Put the necessary client files in the client bucket, and make the files (not the bucket) publicly readable.

3

Create a distribution for your client (or you can use an existing distribution). You can use the CloudFront control API or your favorite CloudFront tool. For a list of tools, go to Amazon CloudFront Developer Tools.

For information about creating a basic distribution with the control API, go to POST Distribution in the Amazon CloudFront API Reference.

4

Put your media files in the streaming bucket, and make the content (not the bucket) publicly readable.

The client bucket and streaming bucket can be the same bucket, or different ones.

5

Use the CloudFront API (or your favorite CloudFront tool) to create a streaming distribution. For more information, see Creating a Streaming Distribution.

6

Configure your client player. For more information, see Playback Client Configuration.


If you have trouble getting your content to play, see Troubleshooting.

Creating a Streaming Distribution

Creating a streaming distribution is almost identical to creating a basic distribution. The easiest way is to use the AWS Management Console at http://aws.amazon.com/console.

To create a streaming distribution with the AWS Management Console

  1. Log in to the AWS Management Console and click the Amazon CloudFront tab.

  2. Click Create Distribution.

    The Create Distribution dialog box opens.

  3. Select the Streaming button to specify a streaming distribution.

  4. In the Origin list, select the bucket you want as your origin server.

  5. Leave the remaining items as they are and click Create.

    Your new streaming distribution is created and appears in the list of distributions on the page. You can select the check box for the distribution to view its information at the bottom of the page.

The CloudFront control API also provides a set of actions for creating and managing your streaming distributions. The actions are parallel to those for creating and managing basic distributions. The main difference is that the resource is a streaming-distribution instead of a distribution. For information about the API actions for streaming distributions, go to the Amazon CloudFront API Reference.

To create a streaming distribution with the control API

  1. Send a CloudFront control API request that looks similar to the following example.

    POST /2009-12-01/streaming-distribution HTTP/1.1
    [Required headers]
    
    <?xml version="1.0" encoding="UTF-8"?>
    <StreamingDistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2009-12-01/">
      <Origin>mystreamingbucket.s3.amazonaws.com</Origin>   
      <CallerReference>20091130090000</CallerReference>
      <Comment>My comments</Comment>
      <Enabled>true</Enabled>
    </StreamingDistributionConfig>
  2. You will receive a response that looks similar to the following example.

    201 Created
    Location: https://cloudfront.amazonaws.com/2009-12-01/streaming-distribution/EGTXBD79H29TRA8
    x-amz-request-id: request_id
    
    <?xml version="1.0" encoding="UTF-8"?>
    <StreamingDistribution xmlns="http://cloudfront.amazonaws.com/doc/2009-12-01/">
       <Id>EGTXBD79H29TRA8</Id>
       <Status>InProgress</Status>
       <LastModifiedTime>2009-11-19T19:37:58Z</LastModifiedTime>
       <DomainName>s5c39gqb8ow64r.cloudfront.net</DomainName>
       <StreamingDistributionConfig>
          <Origin>mystreamingbucket.s3.amazonaws.com</Origin>
          <CallerReference>20091130090000</CallerReference>
          <Comment>My comments</Comment>
          <Enabled>true</Enabled>
       </StreamingDistributionConfig>
    </StreamingDistribution>
  3. Store the Location header from the response, which contains the URI for your newly created streaming distribution, the ID for the distribution, and the domain name.

Playback Client Configuration

To play a media file, you need to configure the client player with the correct path to the file. How you configure the client depends on which client you're using, and how you're using it.

When you configure the client, the path you specify to the media file must contain the characters cfx/st immediately after the domain name. For example, rtmp://s5c39gqb8ow64r.cloudfront.net/cfx/st/mediafile.flv.

Your client might ask for the path separate from the file name. For example, with JW Player's wizard, you specify a streamer and file variable, like so:

  • streamer—rtmp://s5c39gqb8ow64r.cloudfront.net/cfx/st (with no trailing slash)

  • file— mediafile.flv

If you've stored the media files in a directory in your bucket (e.g., videos/mediafile.flv), then the variables for JW Player would be:

  • streamer—rtmp://s5c39gqb8ow64r.cloudfront.net/cfx/st (with no trailing slash)

  • file— videos/mediafile.flv

To use the JW Player wizard, go to http://www.longtailvideo.com/support/jw-player-setup-wizard?example=204.

MPEG Files

To serve MP3 audio files or H.264/MPEG-4 video files, you might need to prefix the file name with mp3: or mp4:. Some clients can be configured to add the prefix automatically. The client might require you to specify the file name without the file extension (e.g., magicvideo instead of magicvideo.mp4).

Crossdomain.xml

Adobe Flash Media Server allows the use of a crossdomain.xml file that specifies which domains can access media files in a particular domain. CloudFront supplies a default file that allows all domains to access the media files in your streaming distribution. If you implement a more restrictive crossdomain.xml file, CloudFront ignores it.

Error Codes

The following table lists the error codes that CloudFront can send to your playback client. The errors are part of the string returned with Event.info.application.message or Event.info.description.

ErrorDescription

DistributionNotFound

The distribution is not found

DistributionTypeMismatch

The distribution is not a streaming distribution

InvalidInstance

The instance is invalid

InvalidURI

The URI is invalid

Troubleshooting

If you're having trouble getting your media files to play, check the items in the following table.

Item to CheckDescription

Separate distributions for the client files and media files

The client must be served by a regular HTTP distribution (e.g., domain name d604721fxaaqy9.cloudfront.net), whereas the media files must be served by a streaming distribution (e.g., domain name s5c39gqb8ow64r.cloudfront.net). Make sure you're not using the same distribution for both.

/cfx/st in the file path

Make sure to include /cfx/st in the file's path (for more information, see Playback Client Configuration). You don't need to include /cfx/st in the path to the object in the Amazon S3 bucket.

Problems playing MPEG-4 files

Some clients require mp4: before the file name. Some might also require you to exclude the .mp4 extension. For more information, see MPEG Files.

Port 1935 on your firewall

Adobe Flash Media Server uses port 1935 for RTMP. Make sure your firewall has this port open. If it doesn't, the typical message returned is "Unable to play video." You can also switch to RTMPT to tunnel over HTTP using port 80.

Adobe Flash Player messaging

By default, the Adobe Flash Player won't display a message if the video file it's trying to play is missing. Instead, it waits for the file to show up. You might want to change this behavior to give your end users a better experience.

To instead have the player send a message if the video is missing, use play("vid",0,-1) instead of play("vid").