Advanced Streaming Video Programming

This section walks through how to add streaming video to a rich media ad.

1. Bandwidth Detection

If you need to serve different Flash video content to users of different bandwidths, you will need to edit/modify the code below to check a users’ bandwidth and serve the Flash Video files(s) accordingly.

1.) In the Atlas streaming video code, Find the variable below and Set the following parameter to true.


      ARM_bandwidthDetection = true;

2.) In the Streaming Video script, Find the block of code below and Set the ARM_video_ source variables to the Flash video (FLV) files you want to serve at the various bandwidths (Where _root.movieX; corresponds to the Flash video file(s) defined in the Microsoft Rich Media movie variables on your Links and Descriptions layer).


//Selects a video source based on users bandwidth
  ARM_stream_connection.onBWDone = function (bandwidthVal)
{
    if (bandwidthVal<150) {
      ARM_video_source = _root.movie1
    } else if (bandwidthVal>150) {
      ARM_video_source = _root.movie2
    } else if (bandwidthVal == undefined) {
      ARM_video_source = _root.movie3;
    }

}

Notes: All ARM_video_source variables must be defined. You can choose which ARM_video_ source variable shall contain which Flash video file (low quality, high quality, etc...), or you can have all ARM_video_ source variables call the same Flash Video file.

2. Setting Buffer Time

As a best practice, it is always recommended to set the ad to buffer a specific amount of streamed information before playback begins. Most publishers require the buffer to be 3 seconds long enabling the video stream to flow more smoothly. To do this, you must call the setBufferTime() function, passing it a value, in seconds.

 

By default buffer time is set to 1 second in the streaming video code. If you need to change the buffer time, Edit the ARM_buffer_size variable according to your needs.


      ARM_buffer_size = 3;

3. Streaming from an External Server

You can stream Flash video files from an external streaming server (i.e. not from Microsoft’ servers).

To do so you must define the full path to the Flash video (FLV) file on the external streaming server in your MTK movie variable (found on Links and Descriptions layer)

 

movie1 = “http://externalserverURL/yourVideo.flv”;
movie2 = “”;
movie3 = “”;
movie4 = “”;

 

Then edit the _root.streaming_url variable (found in the Microsoft streaming video code) to call the movie variable that is set to the location of the FLV file.

_root.streaming_url = _root.movie1;

4. NetStream Class Methods & Properties Summary

The following methods and properties of the NetConnection and NetStream classes are used to control FLV playback.

a.) Method summary table for the NetStream class
Methods
Purpose
NetStream.close() Closes the stream but does not clear the video object.
NetStream.pause() Pauses or resumes playback of a stream
NetStream.play() Begins playback of an external file (FLV) file
NetStream.seek() Seeks a specific position in the FLV file
NetStream.setBufferTime() Specifies how long to buffer data before starting to display the stream
b.) Property summary table for the NetStream class
Property
Description
NetStream.bufferLength The number of seconds of data currently in the buffer.
NetStream.bufferTime

Read-only: the number of seconds assigned to the buffer by

NetStream.setBufferTime().

NetStream.bytesLoaded

Read-only; the number of bytes of data that have been

loaded into the player.

NetStream.bytesTotal

Read-only; the total size in bytes of the file being loaded

into the player

NetStream.currentFps The number of frames per second being displayed.
NetStream.time Read-only; the position of the play-head, in seconds.
c.) Event handler summary for the NetStream class
Event Handler
Description
NetStream.onStatus

Invoked every time a status change or error is posted for the

NetStream object.

5. Optimal Encoding Values for Flash Streaming Video

Below are recommended target bitrates for your Flash videos (.flv), and suggestions for encoding parameters to reach those targets. Adjust these settings as necessary to optimize your particular video.

High motion video encoding values; lots of zooms, fades and people moving around.
Quality Target Connection Speed Video Bitrate Width Height FPS Keyframe Interval Audio Bitrate
High 1.5 Mbps 750 Kbps 320 240 29.97 60 96 Kbps
Hight 768 Kbps 575 Kbps 320 240 29.97 60 64 Kbps
Medium 384 Kbps 329 Kbps 320 240 14.98 30 32 Kbps
Low 56k Dial Up 40 Kbps 192 144 9.99 20 8 Kbps
Low motion video encoding values; general talking heads.
Quality Target Connection Speed Video Bitrate Width Height FPS Keyframe Interval Audio Bitrate
High 1.5 Mbps 650 Kbps 320 240 29.97 60 96 Kbps
Hight 768 Kbps 230 Kbps 320 240 14.98 60 64 Kbps
Medium 384 Kbps 153 Kbps 320 240 9.99 20 32 Kbps
Low 56k Dial Up 40 Kbps 192 144 9.99 20 8 Kbps