Recently, I wanted to make a simple animation to put on a webpage. I have a background image and a rendered 3D animation which should be on top of that.
When it comes to lossless image compression, PNG is my all-time favorite. It has layer support, full transparency, lossless non-patented compression, open format, … So the PNG-derived MNG would be a logical choice for animation, right? Wrong! 🙂 Almost none of the current browsers support it out of the box! Mozilla supported it for some time, but gave up due to bloated implementation. Konqueror is the only one supporting MNG! Can you believe that? 😕 Maybe you can, if you see the popularity of Flash. But what if you just want a simple animation? Is the loading of a full flash player justified for a simple animation? And why prefer a closed proprietary format if there are open ones? So I went on a quest for better formats. 🙂
The only as good alternative I could think of is SVG. I remember PNG taking some time before it was accepted. MNG has taken its time but still doesn’t seem accepted. I think SVG has a better chance to get accepted, but is still just a little bit too new. I had a look at animated SVG but my first impression was that it wasn’t that well suited for my purpose of handling prerendered images, but rather for real vector graphics.
So there I was, back at GIF. I contemplated that GIF, after all, wasn’t patented anymore (I know, not GIF itself, but the compression algo in it), so I could forgive myself using it. 😉 So how to encode a bunch of frames into an animated gif? Simple. Just open your favorite shell with ImageMagick support and type something like:
convert *.png test.gif
You can define a transparent color, but if your input is already PNG, there’s no need to specify that of course. I tried several commands from premerging the background to scaling to translating until I got stuck at the latter. Somehow the translation didn’t work… I decided it was getting too clumpsy anyway, so I burned my foreground into the background in the Blender phase, since this was the first thing I did anyhow before merging into GIF. Btw, I found out, Blender has about 4 ways to achieve this same result. 🙂
But… when I finally got the result, I regretted my choice for GIF a bit.. Thinking of a small band user like my brother, ~280KB for a simple 30 frames animation is a bit too much.. 😉 I knew the GIF format would be inefficient, but still hoped for a good result. It’s obvious that the background storage is inefficient (unless someone can tell my that GIF has layer support?).
So, just to know the difference with flash 😉 I searched the net for a way to generate a flash movie with open source tools only. The solution came in the form of swftools. Swftools provides a (questionable?) script language to script your animation. I have no idea if it is a known scripting language as I don’t know anything about flash. 😉 Anyhow, I have rendered files like 0001.png, 0002.png, etc so it would need some rather repetitive work to create that script (I didn’t find any way to define loops in the script language). For some reason I judged it was overkill to write a program in C, java or C# just for generating a script, so I deemed a scripting language much more adequate for the job. Let’s see, which scripting language then.. 🙂 Windows shell script? not familiar enough with. I did some Perl a while ago, but found out I didn’t install it yet on this PC. Mmm, what’s installed.. Python?! But without IDE. Oh well, everyone says it’s so easy, right? 😉 After some fumbling around to get the formatted strings working in file output, I finally came up with a script that does the job. 🙂
I’ll post it here in case some Python guru feels the need to educate a noob (meaning, comments welcome ;)):
outputfile=open('makesc.out', 'w') for i in range(1,30): num = str(i); outputfile.write(".frame "+num+'n'); outputfile.write('t.png frame'+num+' "'+num.zfill(4)+'.png"n'); outputfile.write('t.put frame'+num+' x=65 y=10n'); outputfile.close();
Does anyone know a great Python reference? Like CHM style, with index, full text search and stuff..
Okay, so having a swftools script, I finally get a flash version of my animation. From 270 to 69KB, not bad…
I’ll guess I have to accept the fact that Flash is everywhere and browser are optimized for it anyhow (tell me that’s true ;)).
I’m still interested in alternatives for web animation formats.. And does anyone know how SWFTools perform in comparison with the commercial Adobe/Macromedia tools?