A script data tag, type 18, holds a single method call: a name and its arguments,
encoded in AMF0, Action Message Format version 0, which Flash Player hands to the
NetStream object playing the file. The usual one is onMetaData, followed by
an ECMA array of the file’s properties. Adobe documents AMF0 (2007) and AMF3 (2013) in
specifications of their own; the FLV specification names AMF0’s types 0 to 12.
SCRIPTDATA
The data is the ScriptTagBody, or, in an encrypted tag, the EncryptedBody (see
Encryption; the
onMetaData tag is always left in the clear).
| ScriptTagBody field | Type | Meaning |
|---|---|---|
| Name | SCRIPTDATAVALUE | The method or object name: a String (type 2). |
| Value | SCRIPTDATAVALUE | The arguments or the object’s properties: for onMetaData, an ECMA array (type 8). Calls with more than one argument carry more values. |
SCRIPTDATAVALUE
Each value is a one-byte type marker, then its data. Numbers are big-endian.
| Type | Name | Data |
|---|---|---|
| 0 | Number | DOUBLE: an IEEE 754 double. |
| 1 | Boolean | UI8: 0 is false, anything else true. |
| 2 | String | SCRIPTDATASTRING. |
| 3 | Object | SCRIPTDATAOBJECT: an anonymous object. |
| 4 | MovieClip | Reserved, not supported: no data is defined for it. |
| 5 | Null | None. |
| 6 | Undefined | None. |
| 7 | Reference | UI16: the index of an earlier object, typed object, strict array or ECMA array in the same message, counting from 0 in the order they began. An object that appears twice is sent once, then by reference. |
| 8 | ECMA array | SCRIPTDATAECMAARRAY. |
| 9 | Object end marker | Only inside SCRIPTDATAOBJECTEND. |
| 10 | Strict array | SCRIPTDATASTRICTARRAY. |
| 11 | Date | SCRIPTDATADATE. |
| 12 | Long string | SCRIPTDATALONGSTRING. |
| 13 | Unsupported | None: stands in for a value that could not be serialised (AMF0). |
| 14 | RecordSet | Reserved, not supported (AMF0). |
| 15 | XML document | A long string: the XML as text (AMF0). |
| 16 | Typed object | A SCRIPTDATASTRING class name, then the properties as in an object (AMF0). |
| 17 | Switch to AMF3 | The avmplus-object-marker: the value that follows is in AMF3 (AMF0, since Flash Player 9). |
Types 13 to 17 come from the AMF0 specification; the FLV specification lists only 0 to 12.
| Structure | Fields |
|---|---|
| SCRIPTDATASTRING | StringLength UI16, then StringData: UTF-8 with no terminating zero, up to 65,535 bytes. |
| SCRIPTDATALONGSTRING | StringLength UI32, then StringData. |
| SCRIPTDATAOBJECTPROPERTY | PropertyName SCRIPTDATASTRING, then PropertyData SCRIPTDATAVALUE. |
| SCRIPTDATAOBJECT | ObjectProperties SCRIPTDATAOBJECTPROPERTY[], then a SCRIPTDATAOBJECTEND. |
| SCRIPTDATAOBJECTEND | ObjectEndMarker UI8[3]: 00 00 09, an empty property name and marker 9. |
| SCRIPTDATAECMAARRAY | ECMAArrayLength UI32, the approximate number of items, then Variables SCRIPTDATAOBJECTPROPERTY[], then a SCRIPTDATAOBJECTEND. All keys are strings, even numeric ones; readers read pairs until the end marker rather than trust the count. |
| SCRIPTDATASTRICTARRAY | StrictArrayLength UI32, then exactly that many SCRIPTDATAVALUEs; no end marker. Gaps in a sparse array are sent as Undefined. |
| SCRIPTDATADATE | DateTime DOUBLE, milliseconds since 1 January 1970 UTC; then LocalDateTimeOffset SI16, the local time offset from UTC in minutes (negative west of Greenwich). The AMF0 specification calls the offset reserved and says it should be 0. |
AMF3 values
After marker 17 one value follows in AMF3, the encoding of ActionScript 3. AMF3 keeps three reference tables: strings, objects and class traits, all started afresh with each message (each tag). A string, object or set of traits sent once can then be sent as an index. Integers and lengths use U29, a variable-length unsigned number of 1 to 4 bytes: the first three bytes give 7 bits each with the top bit set when another byte follows, and a fourth byte gives all 8 bits.
| Marker | Type | Data |
|---|---|---|
| 0 | undefined | None. |
| 1 | null | None. |
| 2 | false | None. |
| 3 | true | None. |
| 4 | integer | U29: a 29-bit signed integer. |
| 5 | double | DOUBLE. |
| 6 | string | UTF-8-vr: a U29 whose low bit is 1 for a string of (U29 >> 1) bytes that follows, or 0 for the index (U29 >> 1) of an earlier string. The empty string is never sent by reference, nor added to the table. |
| 7 | XMLDocument | U29: low bit 0, an object reference; 1, a length, then the XML as UTF-8. |
| 8 | date | U29: low bit 0, an object reference; 1, then DOUBLE milliseconds since 1970 UTC. |
| 9 | array | U29: low bit 0, an object reference; 1, the number of dense elements (U29 >> 1); then name and value pairs ended by the empty string; then the dense elements. |
| 10 | object | U29: low bit 0, an object reference. Low bits 01: the traits are a reference (index U29 >> 2). Low bits 011: the traits follow: bit 3 says the object is dynamic, U29 >> 4 is the number of sealed members, then the class name and the sealed member names (strings). Low bits 111: the class is externalizable, its name follows, and the class writes its own data. Then the sealed members’ values, and for a dynamic object name and value pairs ended by the empty string. |
| 11 | XML | As XMLDocument (E4X XML). |
| 12 | ByteArray | U29: low bit 0, an object reference; 1, a length, then the bytes. |
| 13 | Vector of int | U29: low bit 0, a reference; 1, the count; then a UI8 (1 for a fixed-length vector) and the items as 32-bit integers. |
| 14 | Vector of uint | As above, unsigned. |
| 15 | Vector of Number | As above, with DOUBLE items. |
| 16 | Vector of Object | As above, then the item type’s name (a string, * for any type) and the items as AMF3 values. |
| 17 | Dictionary | U29: low bit 0, a reference; 1, the number of entries; then a UI8 (1 for weak keys) and the entries, each a key value and a value, both AMF3 values. |
An externalizable class’s data has a layout only that class knows, so nothing after it can be read, except for Flex’s two wrappers (ArrayCollection and ObjectProxy), which hold one AMF3 value. FLV files rarely contain AMF3.
onMetaData
The file’s properties, in a script data tag named onMetaData (Adobe’s text
spells it onMetadata; files and players use onMetaData).
Which properties are there depends on the program that wrote the file. Adobe lists
these:
| Property | Type | Meaning |
|---|---|---|
audiocodecid | Number | The audio codec: a SoundFormat value, or in Enhanced FLV a FourCC as a number. |
audiodatarate | Number | The audio bit rate in kilobits per second. |
audiodelay | Number | The delay the audio codec adds, in seconds. |
audiosamplerate | Number | The frequency at which the audio is played. |
audiosamplesize | Number | The resolution of a single audio sample. |
canSeekToEnd | Boolean | Whether the last video frame is a key frame. |
creationdate | String | The creation date and time. |
duration | Number | The total duration of the file in seconds. |
filesize | Number | The total size of the file in bytes. |
framerate | Number | Frames per second. |
height | Number | The height of the video in pixels. |
stereo | Boolean | Whether the audio is stereo. |
videocodecid | Number | The video codec: a CodecID value, or in Enhanced FLV a FourCC as a number. |
videodatarate | Number | The video bit rate in kilobits per second. |
width | Number | The width of the video in pixels. |
Enhanced RTMP adds audioTrackIdInfoMap and videoTrackIdInfoMap
for multitrack files; see Enhanced
FLV. Other programs write properties of their own, outside Adobe’s list. The most
common:
| Property | Written by | Meaning |
|---|---|---|
encoder | FFmpeg and others | The program that wrote the file. |
keyframes | flvtool2, yamdi and others | An object of two strict arrays: times (seconds) and filepositions (byte offsets) of the key frames, so a player can seek. |
metadatacreator | flvtool2, yamdi | The program that wrote this metadata. |
hasVideo, hasAudio, hasMetadata, hasKeyframes, hasCuePoints | flvtool2, yamdi | What the file holds. |
lasttimestamp, lastkeyframetimestamp, lastkeyframelocation | flvtool2, yamdi | The time of the last tag and of the last key frame (seconds), and the byte offset of the last key frame. |
datasize, videosize, audiosize | flvtool2, yamdi | Bytes of tag data, of video tags and of audio tags. |
onXMPData
XMP metadata is carried in a script data tag named onXMPData, at time 0:
after any onMetaData tags at time 0 and before the audio and video tags at time 0,
though readers should not rely on the order. Its value is an object with one
property, liveXML (String or Long string): the XMP packet.
Other names
Any method name can be stored; Flash Player calls the NetStream handler of that name. Ones seen in files:
| Name | Meaning |
|---|---|
onCuePoint | A cue point embedded by the encoder: an object with name, time, type (event or navigation) and parameters. |
|AdditionalHeader | The encryption header of an encrypted file; see Encryption. |
onTextData | Timed text. |
onImageData | An image. |
onFI | Frame information (the system date and time code of a frame), written by Flash Media Live Encoder. |
Worked example
The start of the data of an onMetaData tag written by FFmpeg:
| Bytes | Meaning |
|---|---|
02 | Type 2: String |
00 0A | StringLength 10 |
6F 6E 4D 65 74 61 44 61 74 61 | onMetaData |
08 | Type 8: ECMA array |
00 00 00 0D | ECMAArrayLength 13 |
00 08 | PropertyName length 8 |
64 75 72 61 74 69 6F 6E | duration |
00 | Type 0: Number |
3F F0 CC CC CC CC CC CD | 1.05 seconds |
| … | The other properties |
00 00 09 | SCRIPTDATAOBJECTEND |