Parsing swf file header on PHP

Source: Internet
Author: User
Tags php server
Parsing swf file header under PHP
This article transferred from: Http://www.dssky.net

Recently, in the CSDN 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 know the SWF file format, SWF file format specification is open, but also can find quite a lot of directly with PHP processing SWF file, This includes parsing the header, generating the SWF file, 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 the 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.
First of all, Bit_value, the address of the law compression package:
Swfheaderparser
In addition, many foreign websites can find relevant content, here provide two representative address, interested friends can go to see.
About parsing swf file headers with PHP:
Http://www.zend.com/codex.php?id=1382&single=1
About generating SWF files with PHP:
http://freemovie.sourceforge.net/
Related logs
PHP Server Platform Quick Build program ....

  • Related 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.