Adobe Flex 3 Help

Using video metadata

You can use the onMetaData callback handler to view the metadata information in your FLV file. Metadata includes information about your FLV file, such as duration, width, height, and frame rate. The metadata information that is added to your FLV file depends on the software you use to encode your FLV file or the software you use to add metadata information.

var nc:NetConnection = new NetConnection();
nc.connect(null);

var ns:NetStream = new NetStream(nc);
ns.client = this;
ns.play("video.flv");

var vid:Video = new Video();
vid.attachNetStream(ns);
addChild(vid);

function onMetaData(infoObject:Object):void
{
    var key:String;
    for (key in infoObject)
    {
        trace(key + ": " + infoObject[key]);
    }
}

The previous code generates code similar to the following, assuming your FLV file contains cue points and audio:

width: 320
audiodelay: 0.038
canSeekToEnd: true
height: 213
cuePoints: ,,
audiodatarate: 96
duration: 16.334
videodatarate: 400
framerate: 15
videocodecid: 4
audiocodecid: 2

If your video does not have audio, the audio-related metadata information (such as audiodatarate) returns undefined because no audio information is added to the metadata during encoding.

In the previous code, the cue point information was not displaying. In order to display the cue point metadata, you can use the following function which recursively displays the items in an Object:

function traceObject(obj:Object, indent:uint = 0):void
{
    var indentString:String = "";
    var i:uint;
    var prop:String;
    var val:*;
    for (i = 0; i < indent; i++)
    {
        indentString += "\t";
    }
    for (prop in obj)
    {
        val = obj[prop];
        if (typeof(val) == "object")
        {
            trace(indentString + " " + j + ": [Object]");
            traceObject(val, indent + 1);
        }
        else
        {
            trace(indentString + " " + prop + ": " + val);
        }
    }
}

Using the previous code snippet to trace the infoObject parameter in the onMetaData() method creates the following output:

width: 320
audiodatarate: 96
audiocodecid: 2
videocodecid: 4
videodatarate: 400
canSeekToEnd: true
duration: 16.334
audiodelay: 0.038
height: 213
framerate: 15
cuePoints: [Object]
    0: [Object]
        parameters: [Object]
            lights: beginning
        name: point1
        time: 0.418
        type: navigation
    1: [Object]
        parameters: [Object]
            lights: middle
        name: point2
        time: 7.748
        type: navigation
    2: [Object]
        parameters: [Object]
            lights: end
        name: point3
        time: 16.02
        type: navigation

Info objects for onMetaData

The following table shows the possible values for video metadata

:

Parameter

Description

audiocodecid

A number that indicates the audio codec (code/decode technique) that was used.

audiodatarate

A number that indicates the rate at which audio was encoded, in kilobytes per second.

audiodelay

A number that indicates what time in the FLV file "time 0" of the original FLV file exists. The video content needs to be delayed by a small amount to properly synchronize the audio.

canSeekToEnd

A Boolean value that is true if the FLV file is encoded with a keyframe on the last frame that allows seeking to the end of a progressive download movie clip. It is false if the FLV file is not encoded with a keyframe on the last frame.

cuePoints

An array of objects, one for each cue point embedded in the FLV file. Value is undefined if the FLV file does not contain any cue points. Each object has the following properties:

  • type: a string that specifies the type of cue point as either "navigation" or "event".
  • name: a string that is the name of the cue point.
  • time: a number that is the time of the cue point in seconds with a precision of three decimal places (milliseconds).
  • parameters: an optional object that has name-value pairs that are designated by the user when creating the cue points.

duration

A number that specifies the duration of the FLV file, in seconds.

framerate

A number that is the frame rate of the FLV file.

height

A number that is the height of the FLV file, in pixels.

videocodecid

A number that is the codec version that was used to encode the video.

videodatarate

A number that is the video data rate of the FLV file.

width

A number that is the width of the FLV file, in pixels.

The following table shows the possible values for the videocodecid parameter:

videocodecid

Codec name

2

Sorenson H.263

3

Screen video (SWF 7 and later only)

4

VP6 (SWF 8 and later only)

5

VP6 video with alpha channel (SWF 8 and later only)

The following table shows the possible values for the audiocodecid parameter:

audiocodecid

Codec Name

0

uncompressed

1

ADPCM

2

mp3

5

Nellymoser 8kHz mono

6

Nellymoser