SWF metadata parser

16 Apr

Recently I needed to be able to determine the dimensions of SWF (Flash animation) files so I could embed them properly on a web page but I couldn’t immediately find something useful with Google that would perform the task. I am aware of the Hachoir project, but it seemed a bit overkill for my simple use case and a quick try with hachoir-metadata failed to parse my particular SWF file.

Luckily the container section of the SWF file format (which contains the metadata) is rather simple and writing a parser for it turned out to be a nice distraction from my normal duties. The result is hexagonit.swfheader which is a minimal package (no dependencies outside the standard library) that provides a single function that parses SWF files and returns the metadata.

The package comes also with a console script that you can use on the command line to quickly introspect local SWF files. In a buildout you’ll need to use the zc.recipe.egg:scripts recipe to get the script installed.


Posted by on April 16, 2008 in software engineering


Tags: ,

3 responses to “SWF metadata parser

  1. Justin

    April 23, 2008 at 19:39

    You may want to note that this requires at least Python 2.4, or include a fallback for using “reversed”.

  2. Kai Lautaportti

    April 29, 2008 at 9:07

    Hi justin and thanks for the feedback.

    I just pushed hexagonit.swfheader 1.0.1 to the PyPI which is compatible with Python 2.3. Unfortunately 2.3 doesn’t have the doctest.DocFileSuite() function so the test runner is currently broken on 2.3.

  3. JR

    July 22, 2008 at 0:34

    Thanks for this. I was in the exact same predicament. You’re a lifesaver.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: