PHP Stop parsing swf file header

Source: Internet
Author: User
Parsing swf file header under PHP

Recently, in
CSDN
On the forum to see a post, want to implement PHP to get the SWF file frame number of functions, some users replied that it is impossible, in fact, they do not understand the SWF file format, SWF file format specification is open, but also can find quite a lot about directly with PHP processing SWF file, including parsing the file header, Generate SWF files, and so on. Using my spare time, I also wrote a rude parsing swf file class.
To parse the SWF file header, the first thing to figure out is, of course,
SWF file format specification
。 The SWF file format is described in detail in the specification. About the SWF file header, it is made up of the following parts:
+--------+-----+--------+----------+----+----+
| file id | version | file size | Rect field | frame rate | number of frames |
+--------+-----+--------+----------+----+----+
??????? Where the "file id" is 3 bytes, including the file compression flag. The contents of these 3 bytes are "FWS" or "CWS", which begins with ' C ' to indicate that the SWF file is a compressed output (from the Rect field to the end of the file, with the zlib standard for file compression).
??????? "Version" is a byte that stores an unsigned integer of 8 bits in length, and the exported version of the SWF file is stored in that byte in 16 notation, if the exported version is 7, the byte stores the value 0x07 instead of the ASCII value of ' 7 ' (0x37).
??????? The file size store occupies 4 bytes and is a 32-bit unsigned integer that stores the uncompressed SWF file size in 16 binary form, and it is worth noting that the SWF file store is stored according to Little-endian, which is the low byte in front of the "small tail" mode, when parsing, You need to be aware of the byte order. If a SWF file size is 471 bytes, then the 4 bytes, from low to high, the stored content will be 0xd7,0x01,0x00,0x00.
??????? The frame rate occupies two bytes, representing the number of frames played per second, the number of fixed-point numbers that are 8.8 total 16 bits, the integer part at the high (i.e. the second byte), the fractional part in the low (first byte), and the byte alignment. such as decimal 7.5 is indicated as 16 binary is 0x07.80, according to Low in front, high in the rear, this 16 bits will be stored as follows 2 code 10000000 00000111.
??????? The number of frames occupies two bytes and is a 16-bit unsigned integer representing the total number of frames in the SWF file. stored in a way similar to how file size is stored.
??????? It is difficult to understand that the Rect field, which is stored using the "bit value" (bit_value) defined in the SWF file format specification, is a storage feature that saves bytes, but the value is cross-byte. The stored content is the size of the playback window expressed in ' Twip ' (translated to ' twips ', 1pixel = 20twips) units. is divided into Nbits, which indicates the bit_value bit length of the subsequent field, and Xmin,xmax,ymin,ymax represents the minimum and maximum values in the X, Y axis direction respectively.
??????? Let's start with the Bit_value, which is characterized in that, regardless of byte distinction, the value is stored consecutively, in the last byte, with 0, for example, two 9-bit unsigned value 7, 8 for 3 bytes, and 2 for binary:
??????? 00000011 10000010 00000000
??????? The 3 bytes are joined in bits, the first 9 bits are 7, the 9 bits are 8, and all the other slots in the 3rd byte are all 0. A simple understanding of the bit_value representation, and the RECT structure, the first 5 bits (bit) of the field is the Nbits field, indicating the bit_value bit length of the subsequent field, is an unsigned number, which means the maximum value is 31, so that The maximum length of the entire rect field is 17 bytes, which means that the SWF file header does not exceed 29 bytes. Once the bit_value bit length of the subsequent field is obtained through the Nbits field, the specific length of the rect can be determined, and then the storage location of "frame rate" and "frame number" is learned. In the Rect field, starting with the 6th bit, the size data of the playback window is stored, and the corresponding values are calculated according to the nbits value, separated by a bitwise of the subsequent parts. However, the SWF file identified as "CWS", starting from the "File Size" field (that is, starting after the 8th byte), is compressed according to the zlib standard, so, when parsing the SWF file header, you first need to determine whether the SWF file is exported in the compressed format. If you are exporting in a compressed format, you need to unpack the contents after the first 8 bytes, and then work with the Rect field and the frame rate and frame number fields.
Here is the address of the SWF file header resolution class and the instance compression package I wrote:
???????
Swfheaderparser

??????? In addition, many foreign websites can find relevant content, here provide two representative address, interested friends can go to see.?
This article transferred from: http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/825.html
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.