PHP停解析swf文件头
PHP下解析swf文件头
近日,在
CSDN
论坛上看到一个帖子,想要实现用PHP来得到swf文件帧数的功能,一些网友回复说不可能,其实是他们对swf文件格式不了解,swf文件格式规范是开放的,而且也可以找到相当多的关于直接用PHP处理swf文件的,包括解析文件头,生成swf文件等。利用闲暇时间,我也写了一个粗陋的解析swf文件的类。
要想解析swf文件头,首先要弄清楚的当然是
swf文件格式规范
。规范中对swf文件格式作了详细的说明。关于swf文件头,它是由以下几个部分组成:
+--------+-----+--------+----------+----+----+
|文件标识|版本|文件大小|RECT字段|帧频|帧数|
+--------+-----+--------+----------+----+----+
??????? 其中“文件标识”为3个字节,包括文件压缩标志。这3个字节的内容为“FWS”或“CWS”,以‘C’开头的表示swf文件是采用的压缩输出(从RECT字段开始至文件结尾,采用Zlib标准进行文件压缩)。
??????? “版本”为一个字节,存储8位字长的无符号整数,将swf文件的导出版本以16进制方式存储在该字节,如导出版本为7,则该字节存储值为0x07,而不是‘7’对应的ASCII值(0x37)。
??????? “文件大小”存储占用4个字节,为32位无符号整数,将未压缩的swf文件大小以16进制形式存入该4个字段,值得注意的是,swf文件存储是按照little-endian,即低字节在前的“小尾”方式存储的,解析时,需要注意字节序。如一个swf文件大小为471字节,则该4个字节,由低位到高位,存储的内容将是0xd7,0x01,0x00,0x00。
??????? “帧频”占用两个字节,表示每秒播放的帧数,存储方式是8.8共16位的定点数,整数部分在高位(即第二个字节),小数部分在低位(第一个字节),并按字节对齐。如小数7.5表示为16进制是0x07.80,按照低位在前,高位在后表示,这16位将存储为如下的2进制代码10000000 00000111。
??????? “帧数”占用两个字节,为16位无符号整数,表示swf文件的总帧数。存储方式类似于“文件大小”存储方式。
??????? 难理解的是RECT字段,该字段采用swf文件格式规范中定义的“位值”(bit_value)进行存储的,这种存储特征是可以节约字节数,但数值是跨字节的。该段存储内容是用‘twip’(翻译为‘缇’,1pixel = 20twips)单位表示的播放窗口的尺寸。分为Nbits,表示后面字段的bit_value位长;Xmin,Xmax,Ymin,Ymax分别表示X,Y轴方向上的最小和最大值。
??????? 先说一下bit_value,其特点是不管字节区分,按照最小位数(bits)将值连续存储,在末字节中空位补0,比如两个9位表示的无符号值7,8将占用3个字节,表示为2进制就是:
??????? 00000011 10000010 00000000
??????? 将3个字节按位连在一起,前9位值为7,再9位值为8,在第3个字节的其他空位全部补0。简单了解了bit_value表示方式,再说RECT结构,该字段前5位(bit)为Nbits字段,表示后面字段的bit_value位长,是一个无符号数,也就是说最大值为为31,如此一来,整个RECT字段的最大长度为17个字节,也就是说swf文件头最大不超过29个字节。通过Nbits字段得到后面字段的bit_value位长后,就可以确定RECT的具体长度,继而得知“帧频”和“帧数”的存储位置。在RECT字段中,从第6位开始,存储的是播放窗口的尺寸数据,根据Nbits值,将后面的部分按位分开计算,即可得到相应值。但对文件标识为“CWS”的swf文件,从“文件大小”字段后面开始(即从第8个字节后面开始),是按照Zlib标准压缩存储的,所以,在解析swf文件头时,首先需判断swf文件是否按照压缩格式导出的。如果是以压缩格式导出的,则需先对头8个字节后面的内容进行解压缩处理了,再来处理RECT字段和“帧频”和“帧数”字段。
下面给出我写的swf文件头解析类及实例压缩包的地址:
???????
swfHeaderParser
???????另外,在国外的许多网站上可以找到相关的内容,这里提供两个有代表性的地址,有兴趣的朋友可以去看看。?
本文转自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/825.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



1 bit is equal to one-eighth of a byte. In the binary number system, each 0 or 1 is a bit (bit), and a bit is the smallest unit of data storage; every 8 bits (bit, abbreviated as b) constitute a byte (Byte), so "1 byte ( Byte) = 8 bits”. In most computer systems, a byte is an 8-bit (bit) long data unit. Most computers use a byte to represent a character, number, or other character.

The redis test code in this article is based on the following environment: Operating system: MacOS 64-bit version: Redis5.0.764bit Operating mode: standalonemode Redis bit operation reids bit operation is also called bit array operation and bitmap. It provides four commands: SETBIT, GETBIT, BITCOUNT, and BITTOP. For manipulating binary bit arrays. Let’s first look at a wave of basic operation examples SETBIT syntax: SETBITkeyoffsetvalue is: command key offset 0/1 The setbit command is used to write the binary bit setting value of the specified offset in the bit array. The offset starts counting from 0 and is only allowed Write 1 or 0,

1byte equals 8bit. Data storage is in "byte" (Byte) as the unit, and data transmission is mostly in "bit" (bit) as the unit. One bit represents a 0 or 1 (that is, binary), and every 8 bits (bit) form a Byte is the smallest unit of information; therefore, "1Byte=8bit".

SWF is a vector-based Flash animation file format that is widely used in web design, animation production and other fields. SWF files are also often called Flash files. FLASH software is generally used to create and generate SWF file formats, and PDF and other types can also be converted to SWF format through corresponding software; SWF can be opened with Flash Player, and the browser must have the Flash Player plug-in installed. Designers and developers can use it to create presentations, applications, and other content that allows user interaction.

CentOS is a Linux distribution that originated from RHEL and is compiled in accordance with the regulations of open source code. Moreover, it maintains functional compatibility with RHEL and is a free, open source operating system that users can use and modify without paying copyright fees. So does CentOS distinguish between 32-bit and 64-bit in Linux? Please see below for details. CentOS distinguishes between 32-bit and 64-bit! The main differences: CentOS32bit system is mainly released for PC; CentOS64bit system is mainly aimed at large-scale scientific computing; 64bitLinux system is mainly installed on 64bit hardware system; 32bit

1 byte is equal to 8 bits. In the binary number system, each 0 or 1 is a bit (bit), and a bit is the smallest unit of data storage; every 8 bits (bit, abbreviated as b) constitute a byte (Byte), so "1 byte ( Byte) = 8 bits”. In most computer systems, a byte is an 8-bit unit of data. Most computers use a byte to represent a character, number, or other character.

Pi Coin In-depth Analysis: Pi Coin (π), a cryptocurrency that coexists with opportunities and challenges, has attracted more than 47 million users worldwide since its birth in 2018 with its unique "mobile mining" mechanism. This article will explore the basic information, ecosystem, application scenarios and the controversy surrounding Picoin, helping you to fully understand this controversial digital asset. Pi Coin Core Information Chinese Name: Pai Coin English Name: Pi Coin, π Coin Common Abbreviation: π Official Website: https://minepi.com/ Founder: Nicolas Kokkalis (Technical Head, Ph.D., Stanford University) and Chengdiao

Many friends have downloaded files in swf format, but cannot open them and need to convert them to mp4 format files. Today I will teach you how to use Format Factory to convert to mp4 format, which is very convenient and fast. Let’s take a look at the specific tutorial below. Method to convert swf format to MP4 format 1. First download the video converter, 2. After downloading and installing, enter the software, select "Video Conversion" on the left and click "Add File", 2. Then select "Output" in "Output Format" Format" and "Output Quality", 3. Then click the "Convert" function on the right. It is recommended to use "Extreme Speed Mode", which can increase the speed by 30%. 4. After the video is converted, you can click "Open Folder" on the right to jump Transfer to the corresponding folder.
