PHP Classes

SWF header parser: Parse header of Flash files to extract metadata

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 73%Total: 5,404 All time: 474 This week: 54Up
Version License PHP version Categories
swfheader 1.0.0GNU Lesser Genera...3Files and Folders, Flash, Parsers
Description 

Author

This class is meant to parse the header of Shockwave Flash animation files (.swf) to extract metadata information like the width and height of animation, compression status and uncompressed size, frame rate and total number of frames.

This class parses Flash files using only PHP code, so no special extension is necessary.

Supports both, compressed and uncompressed SWF Flash movies

Innovation Award
PHP Programming Innovation award nominee
May 2004
Number 2


Prize: One downloadable copy of PHPEd
Shockwave Flash is a technology that has been growing its popularity in the latest years, especially among Web designers.

It provides a much richer means of presentation of content and user interaction that the traditional HTML based user interface pages.

This characteristic has been motivating many Content Management System developers to add support to integrate Flash animations in their systems.

The Shockwave Flash format is proprietary and is made of binary information. This imposes an additional difficulty to analyze and verify the integrity of the information contained in Flash animation files.

This class provides a basic solution for analyzing Flash animation files by parsing their header information to extract metadata that may be useful for content management systems as well verify the integrity of these files when they are uploaded to the publishing systems.

Manuel Lemos
Picture of Carlos Falo Hervás
Name: Carlos Falo Hervás <contact>
Classes: 10 packages by
Country: Spain Spain
Age: 49
All time rank: 361 in Spain Spain
Week rank: 170 Down5 in Spain Spain Down
Innovation award
Innovation award
Nominee: 1x

Details

===== BASIC DOCUMENTATION FOR SWFHEADER CLASS ===== 0.- INTRODUCTION AND EXTENTS I implemented this class to allow for native PHP coding support to get basic information from SWF files (i.e. to allow dynamic SWF banner systems with non-fixed banner sizes or flash versions) I will be working a bit more on this class and maybe I'll be merging it with file_finder class for a common locate-and-show class. 1.- BASICS OF OPERATION The class works on 4 basic functions PUBLIC INTERFACE VARIABLES: valid : boolean - The processed file was vaild fname : string - Filename of the file we parsed compressed : boolean - True on compressed files, file size won't match value in size member variable (see below) version : numeric - Flash version for the file (useful for generating OBJECT plug-in check) width : numeric - Movie width (pixels) height : numeric - Movie height (pixels) size : numeric - Size in bytes for the movie, it is the uncompressed size so might not mach the real file size on movies that are compressed (see compressed above) frames : numeric - total frames in the movie fps[] : Array - 2 values array holding FPS in 8.8 (array[1].array[0]) format PUBLIC INTERFACE METHODS: function swfheader($debug=false) ; The constructor: $debug -> determine if the class shows debug information while processing the file Just creates the object and initialized it to "empty" values function init() Initialization Clears all data from previous uses function loadswf($filename) ; The SWF header parser: $filename -> file (with full path) to parse Opens the file and gets all the info from it's header (based on Flash 6/MX specs). Returns 1/0 on success/error function show() ; Print report: Shows on-screen a report for all the analyzed file data function display($trans = false, $qlty = "high", $bgcolor = "#ffffff", $name = "") ; Echo <OBJECT>/<EMBED> code for the loaded file: $trans -> transparency (boolean) sets WMODE to transparent if true $qlty -> movie quality "high" or "low" $bgcolor -> background color for the movie (if not $trans) $name -> ID/NAME for the object/embed, defaults to fname without .swf extension Generates HTML <OBJECT> & <EMBED> code for the parsed file based on the data just gathered from the header information. 2.- Tech notes In order to manage CWS (compressed) files the class MUST simulate a buffer meaning it has to read the full file on a string and fetch characters manually, making it a bit memory hungry for big files (wich also might need to decompress in memory). 3.- The SWF header format This information is based on Macromedia Flash MX official SWF format specs and some hex reading in real files itself. MAGIC : 3 bytes, 'F' or 'C', 'W', 'S', a C on the first byte states compression VERSION : 1 byte, i.e. 5 , 6, 7 SIZE : 4 bytes, uncompressed size in LSB-MSB format ([0]+[1]<<8+[2]<<16+[3]<<32) If file is compressed, a GZ stream starts here (0x78 indicating DEFLATE) RECT : variable size, RECT struct for the movie dimensions (see below) PACKED FRAMES : 2 bytes in LSB-MSB format ([0]+[1]<<8) FPS : 8 bytes in 8.8 ([1].[0]) format RECT struct information: N_BITS : 5 bits, shows the number of bits for each of the following sections MIN_X : N_BITS bits, min. X coord MUST BE 0 MAX_X : N_BITS bits, min. X coord (width is MAX_X - MIN_X : GENERIC) MIN_Y : N_BITS bits, min. Y coord MUST BE 0 MAX_Y : N_BITS bits, min. Y coord (width is MAX_Y - MIN_Y : GENERIC) This struct is PACKED (bit '0' padded to the end of last used byte) 4.- License SWFHEADER CLASS - PHP SWF header parser Copyright (C) 2004 Carlos Falo Hervás This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 5.- Future releases and WIP I don't think i'll work much on this class, but any new release will be posted at http://phpclasses.upperdesign.com Any suggestions are appreciated 6.- Contact information Carlos Falo Hervás slainte@jet.es

  Files folder image Files (4)  
File Role Description
Accessible without login Plain text file LICENSE.txt Lic. LGPL license
Accessible without login Plain text file README_EN.txt Doc. English documentation
Plain text file swfheader.class.php Class Base class source code
Accessible without login Plain text file test.php Example Test script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:5,404
This week:0
All time:474
This week:54Up
User Ratings User Comments (5)
 All time
Utility:95%StarStarStarStarStar
Consistency:87%StarStarStarStarStar
Documentation:87%StarStarStarStarStar
Examples:80%StarStarStarStarStar
Tests:-
Videos:-
Overall:73%StarStarStarStar
Rank:145
 
Still works after almost 15 years.
3 years ago (John Trouble)
80%StarStarStarStarStar
Really, really nice.
14 years ago (Bruno Tacca)
77%StarStarStarStar
Awesome class ;) thanks!
14 years ago (Adrian)
80%StarStarStarStarStar
Works well.
15 years ago (F Philip DeGeorge)
75%StarStarStarStar
Very good class, nice alternative to getimagesize that uses s...
16 years ago (jarosek)
75%StarStarStarStar