The AMF (Action message Format) is a common binary encoding mode for Flash and server communications, which is highly efficient and can be transmitted at the HTTP level. Many flash webgame now use such a message format.
The AMF protocol is based on the HTTP protocol.
Its content processing process is roughly like this:
1. Get the HTTP request (requests) stream from the client.
2. Convection for serialization (deserialize), get the data that the server-side program can recognize and establish a response (Response) message
3.Debug start
4. Convection for various processing (records, licenses, services) to get the return value
5. Serialization of response streams
6. Send HTTP response to client standard documentation:
This type of tag is also commonly known as metadata tag, and will put some parameter information about FLV video and audio, such as duration, width, height, and so on. Usually this type of tag will appear as the first tag after the file header, and there is only one. ( the tag information generally needs to be with the player to agree on a good name and numerical relationship, if not agreed, the player will be directly discarded )
One of the tools associated with this is: Yamdi
Yamdi adds a lot of metadata information to the FLV file, such as creator, key frame, video, audio, video height and width, and so on. The most effective of the meta data added to Yamdi is the number of keyframes. The FLV injected with the key frame can achieve the same "drag progress" as a large video web site like Tudou, Youku, and drag ahead to the point where the buffer has not yet been loaded.
In general, the tag data structure contains two AMF packets. The AMF (Action message format) is a generic data encapsulation format that Adobe designs, and is used in many Adobe products, and in simple terms, AMF describes different types of data in a uniform format. The first AMF package encapsulates string type data that is used to load a "onmetadata" flag, which is not detailed in some of Adobe API calls. The second AMF package encapsulates an array type that contains the name and value of the audio and video information item. Details as follows, you can refer to the data on the picture to understand.
First AMF Package:
The 1th byte represents the AMF package type, which is always 0x02, represents a string, and other values indicate meaning. Please consult the documentation.
The 第2-3个 byte is a UI16 type value that represents the length of the string and is generally always 0x000a ("onmetadata" length).
The following bytes are string data and are generally "onmetadata".
Second AMF Package:
The 1th byte represents the AMF package type, which is always 0x08 and represents an array.
The 第2-5个 byte is a UI32 type value that represents the number of array elements.
The following is the encapsulation of each array element, and the array element is a pair of element names and values. The representation method is as follows:
The 第1-2个 byte represents the length of the element name, which is assumed to be L.
followed by a string of length L.
The l+3 byte represents the type of the element value.
followed by the corresponding value, the number of bytes depends on the type of value
Cyclic parsing scripttagbody
1. Analytic scriptdatavalue
1.1 Parsed data type type is the data type after the 8-bit representation (0,number; 1,boolean;2,string ...). 8,ECMA array ..... )
1.2 Analysis of different data types of specific data according to the following table
Number,double (parse a double data)
Boolean,ui8 (parsing a byte data)
String, parsing by table scriptdatastring
.........
ECMA array is parsed according to the table Scriptdataecmaarray
1.2.1 Takes scriptdatastring as an example to resolve:
Stringlength data length of 16 digits indicates the length of the data
ASCII code for stringdata 16-bit data
1.2.2 takes Scriptdataecmaarray as an example to resolve:
Ecmaarraylength 32-bit array length
Variables Each data resolution is shown in table Scriptdataobjectproperty
1.2.2.1 Table Scriptdataobjectproperty
PropertyName Data name resolution see table scriptdatastring see above 1.2.1
Propertydata data value analysis See table Scriptdatavalue see 1.
List Terminator resolution see table Scriptdataobjectend (array end bit, accounting for 3 bytes must be 0x 00 00 09)
An example of a tag in the selected area is the following figure:
Tag header information: 11 bytes 12 00 01 74 00 00 00 00 00 00 00 Script Data (0x size = 0x00 01 74)
Data type: 0x 02 indicates string type
Stringlength data length of 16 digits: 0x 0A length 10
StringData value: 0x 6F 6E 4D 61:onmetadata
Data type: 0x 08 means ECMA array array type
Ecmaarraylength 32-bit array length current value: 0x 00 00 00 10 Array Length: 16
1) PropertyName Data name
Stringlength data length of 16 digits: 0x 00 08 Length 8
StringData value: 0x, 6e:duration, 6F
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x:40 A8 F5 C2 8F 5C 29 Value: 133.28
Convert code:
#include "stdio.h"
int main ()
{
Union double
{
double ;
__int64 data;
DOUBLE num;
Num.data = 0x4060a8f5c28f5c29;
printf ("%lf\n", num.number);
GetChar ();
return 0;
}
2) PropertyName Data name
Stringlength data length of 16 digits: 0x 00 05 Length 5
StringData Value: 0x 68:width
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x 40 84 00 00 00 00 00 00 Value: 640.00
3) PropertyName Data name
Stringlength data length of 16 digits: 0x 00 06 Length 6
StringData Value: 0x 74:height
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x 40 76 80 00 00 00 00 00 Value: 360.00
4) PropertyName Data name
Stringlength data length of 16 digits: 0x 0D length 13
StringData value: 0x-A-$ 6F 65:videodaterate
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x A4 B4 00 00 00 00 Value: 282.29
5) PropertyName Data name
Stringlength data length of 16 digits: 0x 00 09 Length 9
StringData value: 0x to 6D 65:framerate
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x 40 39 00 00 00 00 00 00 Value: 25.00
6) PropertyName Data name
Stringlength data length of 16 digits: 0x 0C length 12
StringData value: 0x-A-$ 6F (6F) 64:videocodecid
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x 1C 00 00 00 00 00 00 Value: 7.00
7) PropertyName Data name
Stringlength data length of 16 digits: 0x 0D length 13
StringData value: 0x-A-65:audiodaterate 6F
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x 5F 74 50 00 00 00 00 Value: 125.82
8) PropertyName Data name
Stringlength data length of 16 digits: 0x 0F length 15
StringData value: 0x, 6F, 6D, 6C, 65:audiosamplerate
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x E5 88 80 00 00 00 00 Value: 44100.00
9) PropertyName Data name
Stringlength data length of 16 digits: 0x 0F length 15
StringData value: 0x, 6F, 6D, 6C, 7A 65:audiosamplesize
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x 40 30 00 00 00 00 00 00 Value: 16.00
PropertyName Data Name
Stringlength data length of 16 digits: 0x 00 06 Length 6
StringData Value: 0x 6f:stereo
Propertydata data
Data type 8-bit value: 0x Boolean type
Data: Double for 8 byte value: 0x 40 30 00 00 00 00 00 00 Value: 16.00
One) propertyname data name
Stringlength data length of 16 digits: 0x 0C length 12
StringData value: 0x, 6F, 6F, 64:audiocodecid
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x 40 24 00 00 00 00 00 00 Value: 10.00
) PropertyName Data Name
Stringlength data length of 16 digits: 0x 0B length 11
StringData value: 0x 6D 6A 6F (5F) 6E 64:major_brand
Propertydata data
DataType type is 8-bit: 0x 02 indicates string type
Stringlength data length of 16 digits: 0x 00 04 length 4
StringData value: 0x 6F 6d:isom
PropertyName Data Name
Stringlength data length of 16 digits: 0x 0D length 13
StringData value: 0x 6D, 6E 6F, 5F, 6e:minor_version, 6F
Propertydata data
DataType type is 8-bit: 0x 02 indicates string type
Stringlength data length of 16 digits: 0x 00 03 Length 3
StringData value: 0x 35 31 32:512
) PropertyName Data Name
Stringlength data length of 16 digits: 0x 00 11 length 17
StringData value: 0x 6F 6D 73:compatible_brands, 6C, 5F, and 6E
Propertydata data
DataType type is 8-bit: 0x 02 indicates string type
Stringlength data length of 16 digits: 0x 00 10 length 16
StringData value: 0x $6F 6D 31:isomiso2avc1mp41 6F, 6D
PropertyName Data Name
Stringlength data length of 16 digits: 0x 00 07 Length 7
StringData value: 0x 6E 6F 72:encoder
Propertydata data
DataType type is 8-bit: 0x 02 indicates string type
Stringlength data length of 16 digits: 0x 0D length 13
StringData value: 0x 4C 32:lavf56.15.102 to 2E to 2E
PropertyName Data Name
Stringlength data length of 16 digits: 0x 00 08 Length 8
StringData value: 0x, 6C 65:filesize, 7A
Propertydata data
DataType type is 8 digits: 0x double
Data: Double for 8 byte value: 0x41 5B 2B 4 B 80 00 00 00 Value: 7122222.0
List Terminator resolution see table Scriptdataobjectend (array end bit, accounting for 3 bytes must be 0x 00 00 09)