PHP stop parsing swf file header

Source: Internet
Author: User
Parsing swf file headers under PHP recently, I saw a post on the CSDN Forum, hoping to use PHP to get the swf file frames. some netizens replied that it was impossible, in fact, they do not know about the swf file format, and the swf file format specification is open. In addition, they can find quite a lot about directly using PHP to process swf files, including parsing file headers, generate a swf File. parse the swf file header in PHP.

Recently
CSDN
I saw a post on the forum and wanted to use PHP to get the swf file frames. some netizens replied that it was impossible. In fact, they did not understand the swf file format, swf file format specifications are open, and you can find quite a lot about directly using PHP to process swf files, including parsing file headers and generating swf files. In my spare time, I also wrote a crude class for parsing swf files.
To parse the swf file header, you must first understand
Swf file format specification
. The swf file format is described in detail in the specification. The swf file header consists of the following parts:
+ -------- + ----- + -------- + ---------- + ---- +
| File ID | version | file size | RECT field | frame rate | number of frames |
+ -------- + ----- + -------- + ---------- + ---- +
??????? The "file ID" contains three bytes, including the file compression mark. The content of these three bytes is FWS or CWS. the content starting with 'C' indicates that the swf file adopts the compressed output (starting from the RECT field to the end of the file, use the Zlib standard for file compression ).
??????? The "version" is a byte that stores an unsigned integer with an 8-digit length. the exported swf file version is stored in this byte in hexadecimal format. for example, if the exported version is 7, the storage value of this byte is 0x07, instead of the ASCII value corresponding to '7' (0x37 ).
??????? The "file size" storage occupies 4 bytes, which is a 32-bit unsigned integer. the uncompressed swf file size is saved to the 4 fields in hexadecimal format. it is worth noting that, swf file storage is stored in the small-endian mode, that is, the low-byte front-end mode. Note the byte order when parsing. For example, if the size of a swf file is 471 bytes, the 4 bytes, from low to high, will be stored in 0xd7, 0 x, 0 x, 0x00.
??????? The frame rate occupies two bytes, indicating the number of frames played per second. the storage mode is 8.8 16-bit fixed points in total, and the integer part is at a high level (that is, the second byte ), the fractional part is at the low position (the first byte) and aligned by byte. For example, if the decimal number is 7.5, the hexadecimal value is 0x07.80. if the decimal value is before the decimal value, the hexadecimal value is 10000000.
??????? The number of frames occupies two bytes, which is a 16-bit unsigned integer, indicating the total number of frames in the swf file. The storage method is similar to the "File Size" storage method.
??????? What is hard to understand is the RECT field, which is stored using the "bit_value" defined in the swf file format specification. this storage feature can save the number of bytes, however, the value is cross-byte. The size of the stream play window in units of 'twip' (translated as 'twip', 1 pixel = 20 twips. It is divided into Nbits, indicating the bit_value length of the following fields; Xmin, Xmax, Ymin, and Ymax indicate the minimum and maximum values in the direction of X and y axis respectively.
??????? First, let's talk about bit_value. its feature is that, regardless of the bytes, values are continuously stored based on the minimum number of bits, and 0 is added in the last byte, for example, the two 9-bit unsigned values 7 and 8 occupy three bytes, and the two hexadecimal format is:
??????? 00000011 10000010 00000000
??????? Link the three bytes by bit. the first nine values are 7 and the last nine values are 8. fill in 0 for all other vacancies in the 3rd bytes. A brief understanding of the bit_value representation method, and the RECT structure, the first five bits of this field is the Nbits field, which indicates the bit_value length of the following field, which is an unsigned number, that is to say, the maximum value is 31. as a result, the maximum length of the entire RECT field is 17 bytes, that is, the swf file header cannot exceed 29 bytes. After obtaining the bit_value length of the following field through the Nbits field, you can determine the specific length of the RECT, and then know the storage location of "frame rate" and "number of frames. In the RECT field, the size data of the playback window is stored starting from 6th bits. based on the Nbits value, the subsequent parts are calculated separately by bit to obtain the corresponding value. However, for swf files marked as "CWS", the files are compressed and stored according to the Zlib standard starting from the end of the "File Size" field (that is, starting from the end of 8th bytes, when parsing the swf file header, you must first determine whether the swf file is exported in the compressed format. If the data is exported in the compressed format, extract the content after the first eight bytes, and then process the RECT field and the "frame rate" and "frame rate" fields.
The following shows the swf file header parsing class and the address of the instance compressed package:
???????
SwfHeaderParser

??????? In addition, you can find related content on many foreign websites. Here we provide two Representative Addresses. if you are interested, you can check them out .?
This article

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.