SWFHeaderInfo

| 2 Comments

As I was working on SharpFlash some more this weekend I came across the need to be able to read the width and height of a .swf file from the file itself. After some digging, I found a great reference for the file format (http://www.half-serious.com/swf/format/) and also noticed that the Macromedia documentation is wrong. The first 3 bytes of a compressed swf are "CWS" not "FWC".

Anyhow, I created a C# class for parsing the swf header, and exposing the attributes as C# properties. You can download it here. It works for compressed .swf files as well.

Example usage is in the main method. It looks like this...

public static void Main() 
{			
	SWFHeaderInfo s = new SWFHeaderInfo("C:\\Development\\SWFHeaderInfo\\test.swf");
	Console.WriteLine(s.Status);
	if (s.Status == "OK") 
	{
		Console.WriteLine("Version: " + s.Version);
		Console.WriteLine("Length: " + s.Length);
		Console.WriteLine("xMin: " + s.xMin); // always 0
		Console.WriteLine("xMax: " + s.xMax); // width
		Console.WriteLine("yMin: " + s.xMin); // always 0
		Console.WriteLine("yMax: " + s.yMax); // height
		Console.WriteLine("FrameRate: " + s.FrameRate);
		Console.WriteLine("FrameCount: " + s.FrameCount);
		Console.WriteLine("Compressed: " + s.Compressed);
	}
	
	// keep the input on the screen
	Console.Read();
}

This should be easily adapatable to use on web pages to pull the .swf information from a .swf on the fly and write out the object/embed tags with the correct width and height values.

I'll be providing better documentation in the future. The code is fairly straightforward and documented as it goes along. It should serve as a good learning piece for those interested in either C# or the .swf header, or both.

Comments welcome. Enjoy! If you find some use for this, I'd be interested in hearing it.

2 Comments

It just happened that I come across this webpage.
I have read the file format. and my goal is to
convert avi to swf. I am familar with directShow, which means, I can get the video bits out of video.

I know that I need to be deal with h263videohead tag. I just want to know whether you have previous experience on this. if so, your help is really appreciated.
thanks.

Do you happen to know if it's possible to read background color of swf ?

Leave a comment



About this Entry

This page contains a single entry by darron published on July 5, 2003 10:04 AM.

SharpFlash, a first look was the previous entry in this blog.

More Progress... is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Archives

OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.02