One of the cool things about working for TechSmith is I’ve become interested in some of the *lower* level aspects of the Flash platform—namely the swf file format spec. So with the customary confidence of a programmer with a Political Science degree I set off to see if I could parse the swf header to extract the following information:
After much gnashing of teeth and a quick lesson in bit shifting from Tom Sirgedas, a C++ dev on the Camtasia Studio team, I developed a utility that parses uncompressed swf files. The big caveat is that it only parses uncompressed swf files—being a java rookie, I’m still working on how to “inflate” a compressed swf file.
However, rather than just sitting on this until I find the time and inclination to inflate compressed swf’s I’m going to release this utility / code to the community under the MIT license. If you are a swf file format or java master and want to post back thoughts or ideas I’d certainly appreciate it.
Jar file usage: java -jar swfheader.jar [swf file]
Download java source (code was condensed into a single file for web download).
I’m not sure how useful this is, but it could have some application in server-side code. For instance, perhaps you allow users to upload swf files to a CMS system. When a request to play back the file comes, the server can quickly parse the header for the width and height to be used when generating the embed tags.
The real value here is that of a lightweight example of parsing the header in Java. Reading the file format specification isn’t a whole lot of fun if you’re coming at it from the non-computer science background that many of us in the Flash community have. If you’re interested in a full blown framework for reading and writing swf files with Java checkout Flagstone’s Transform SWF library (and source code).