Quantcast
Channel: Dirty Motherfucking Blog » aswing
Viewing all articles
Browse latest Browse all 4

Converting SWF animations to video

$
0
0

If you ever tried to convert a SWF animation to a video you know what a pain it can be. Let’s first look at the solutions at hand:

  • Exporting a movie from Flash
  • Using a SWF to movie converter
  • Screen capture

Now let’s break those down.

  • Exporting a movie from Flash
    - Doesn’t play sub-movieclip animations
  • Using a SWF to video converter
    - Some have limited encoding support
    - Some have really bad encoding quality
    - Some have poor playback performance and the result looks shitty
    - Some also don’t play sub-movieclip animations
  • Screen capture
    - Suffers from the same encoding and playback problems as converters

So, after trying all of the above on a project at hand i was rather disappointed to see that all the solution i tried were basically shit. The animation at hand had 1024×768 dimensions and only in Flash player 10 it played with reasonable speed. So when i added screen capture into the mix the result looked like crap.

So i rolled my own converter. And the goals were clear:

  • I want to capture every single frame of the animation
  • I want the highest quality possible
  • I want to use the vector scaling of flash to achieve my target size to avoid bitmap scaling later on in the process.

Now what i ended up with is a converter that just writes out every single frame as PNG, no sound, no direct video. But capturing the sound is extremely easy and so is converting a PNG sequence into a movie.

So here is how it’s done.
At first i tried to gotoAndStop( ++frame ); in a loop and writing out the frames, but this results in sub-movieclip animations not being played back.
So what you have to do is just play the movie. But you place a listener on it for Event.ENTER_FRAME. If your host application runs at the same frame rate you can also place the listener on the host application (which is what I’ve done in my reference implementation).

Now in the event listener you just .draw into a BitmapData object, encode it to PNG (using the AsPngEncoder from the AsWing project for example) and then write it to disk.
And this is where you get problems. Cause Flash itself won’t let you write to disk. I had 2 solutions to that problem. I used SWFStudio to compile a .exe that could write binaries to disk and i wrote one version in AIR.

Feel free to look at both implementations, but keep in mind that they are basically proof-of-concept, look like shit and are almost unuseable.

The SWFStudio version expects the name of the swf as the first command-line parameter (which can’t include spaces). The second and third parameter are the width and height. The last parameter is the number of frames to write.

The AIR version includes a GUI to set the input movie and output folder.

Have fun!

SWFStudio Version
Adobe AIR Version


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images