FLV Slow Motion Playback Test
July 13th, 2008
By request I’ve begun developing a Flash video player with slow motion playback cababilities. There are a number of ways to achieve this effect using either Flash or Flex. One way to get slow motion is to simply keep pausing and playing the video at a specific rate. Another way I’ve discovered is to record the currently playing area of the video stream into a bitmap data cache. Then you could just pause the currently playing video and overlay the cached bitmap data, so it appears as if the bitmap data was the actual video object, even though it’s not. Since the second method sounds much more complicated, I decided to give the first method a shot. Surprisingly, the results weren’t as bad as I expected. I have embedded the resulting SWF demonstration in this post, and also provided all of the source files in Flash Professional CS3 format. Special thanks to Peter Wach for the awesome test video footage of a praying mantis eating a live mosquito.
Click here to download source files (2.9mb)The video player utilizes the play / pause method mentioned above. Instead of simply playing and pausing the video at a set interval, I took this a step further. As seen in the actionscript source file, once the slow motion button is enabled, Flash starts a timer (slowTimer). Every 1 millisecond, a status check is performed. By default the status is set to zero. So if the status checks out to be that default zero, Flash immediately pauses the video stream and sets the status to another value. Now every millisecond that goes by, Flash will notice the status isn’t code zero anymore, so it just leaves the video paused at the last displayed frame. Flash will continue to check this status for a set number of intervals until it reaches a certain code (7) which allows the video playback to resume. The status is then reset to zero and the whole process starts all over again.
The reason why I went through all this extra status-checking trouble is because simply toggling the pause / play at a set interval seems to come out a bit sloppy. Some times it looked like slow motion, other times it just looked like someone was randomly tapping the pause button. My method appears a bit more consistent, and isn’t threatened by the bitmap caching method’s increased RAM usage.
The current configuration has a frame-by-frame type of playback effect. This can easily be configured inside the actionscript file by adjusting the slowTimer interval and maximum status count values. The player demonstrated below has a timer interval of 1 millisecond and a maximum status count of 7. You can achieve faster playback by decreasing the maximum status count value, and if this gets too fast then you can always adjust the timer interval…
Check back soon, I may post another version using the bitmap data method!