The title pretty much says it all–this code sample illustrates how to compress a swf file using the Java Deflater class to perform the zlib compression on all the bytes of the swf except for the first 8 bytes which are always uncompressed. This class isn’t intelligent in the sense that it doesn’t check to see if you actually have a valid swf file signature, or check to see that the file is actually uncompressed. So basically you have swf compression in its rawest form.
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:
- file signature
- frame rate
- frame count
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).
After years of resistance I finally caved and bought a sleek, shiny MacBook Pro over the weekend. I’ve been slowly figuring out how to set up my AMES development environment and that means figuring out the basics of using the Unix shell. I struggled to find a simple explanation of how to set environment variables, so I’m inserting a couple of screen grabs which illustrate how to add MTASC and Swfmill to the PATH environment variable.
I downloaded, unzipped and placed the mtasc and swfmill binaries in their respective folders in the following folder:
Method 1 : A Session Variable – Using the bash shell, this adds the mtasc and swfmill binaries to the PATH variable for the current terminal session. When you close the shell and reopen it, you’ll have to add the files to the PATH variable again.
Method 2: Add to Startup Script – Place the command in a startup script called bashrc which can be found along the path below. The modified PATH will always be available to any bash shell and no further editing is needed.
This method is similar to how environment variables are set in Windows (without the gui absraction layer). the bashrc file is a simple text file and you simply add the commands to this script which is run everytime the os loads.
I created 48 minutes worth of tutorials exploring the use of Camtasia Studio, Flash, After Effects and more for my FITC presentation (way more than anyone will be able to stomach, but it was worth not sleeping for a 4 days :) ).
I haven’t updated the rss feed for the podcasts, but will tomorrow so that you can see what they look like in that format. I’m going to try and scratch out a couple of hours of sleep before my 9:00 A.M. presentation tomorrow.
Update: I have updated my itunes podcast feed, so you can now download and watch the screencasts on your video ipod.