Video support in Flash is nothing new. In Flash 8, however, video support has been improved dramatically. Both the new FLVPlayback component and support for an 8-bit alpha channel open up new possibilities for Flash animators and developers. In the past, any Flash "alpha" video had to be hacked together—with less than satisfactory results. In Flash 8 you simply link to a Flash Video (FLV) file that has an alpha channel, and that's it—any objects or animations will show through in the background. This results in vastly improved user experiences in your video-based Flash applications.
This article will help you to get started creating and importing alpha videos into Flash. You will key a sample video file and see a simple application that demonstrates the new alpha video technology. If you are a Flash developer who is interested in gaining a basic knowledge about keying your video and incorporating it into your applications, then this article is for you.
Note: This article is part of a series of articles on new Flash 8 features written by the staff of gskinner.com, a Flash development and consulting company working with leading new-media agencies and progressive corporate clients to create cutting-edge applications, games, and multimedia pieces. Learn more by visiting gskinner.com/blog.
To make the most of this article you need to install the following software and files:
Alpha video in Flash 8 is now available thanks to the incorporation of the On2 VP6 video codec in Flash Player 8. In addition to offering a huge increase in quality over the old Sorensen codec, On2 VP6 enables you to encode an 8-bit alpha channel directly into FLV files.
Users familiar with video editing will know that creating alpha channels is a fairly straightforward process. Any popular video editing application can do this, such as Adobe After Effects, Apple Final Cut Pro, and the Avid suite of products. With the Flash Video Encoder (which works with any of these products), creating alpha channels is as simple as selecting a check box during export to incorporate your alpha channel.
Green- and blue-screen technology is widely used in film and video for keying (short for chroma keying)—the process of extracting a specific color range from a video and replacing that color with transparency (alpha). This technique is commonly used to insert stock footage into a background or composite two scenes into one. To do this, you shoot video against a green- or blue-screen background and then remove it easily in the editing environment.
This process has been around for years in the movie and TV industries but only recently has it become accessible to the general public. When prepping a video for keying, it is important to keep the following in mind:
Know your camera. Because every camera is different, find out what settings it has before you start filming. Here are a few questions to keep in mind when doing this:
For example, in a test shoot our character had a nice orange color before we started shooting it against a solid blue background. However, in our first attempt at filming, the character turned red and the blue background turned dull gray. So, if you can, lock your white balance before shooting. Refer to your owner's manual to achieve the best results you can. This applies to locking your camera's focus too. For a quick result, place a test object on the screen, find the perfect focus level, and then lock it. Or just turn off the autofocus feature altogether and focus manually.
Ultimately if your project requires high-quality video, you will most likely need to hire professional studio and video personnel to film your video for you. If this option is not available, then rent some professional video equipment and set up your shoot in your basement or back room, where you can control the environment the best. For experimental work, you should be able to get away with a consumer camcorder and some bright reading lights.
This section looks at one of the simplest ways to key video for use with Flash 8. The sample files that accompany this article include a video file (Sample.mov), located in the assets directory, with which you can play. Note that the process of keying a video varies from video to video and application to application. The basic process follows these steps:
Open the After Effects Filters panel (Windows > Effects & Presets). You will see a category called Keying (see Figure 1).
Figure 1. Effects & Presets panel showing the open Keying section
The Keying category shows the default keying effects you can use with After Effects.
You can also use plug-ins to expedite this process. If you plan to create a lot of alpha videos, or your project has the budget to cover the cost, you might want to look into using them.
The third setting, Edge Feather, softens the edges from where the color was removed. Setting this to 1.1 gives your video a softened, more final look.
Note: Keep in mind when creating your own alpha video that keying is not the only option available to you. You can also set custom masks, manually erase the background (good for cleaning up open areas that keying cannot remove), or find a plug-in that does a lot of the keying for you. Macromedia video pros recommend dvMatte Pro AE when working with plug-ins for Adobe After Effects. Try different techniques to see what works for you.
When working with the Sample.mov file, I found it necessary to layer four color keys onto the video. What this does is remove the different ranges of green from the background. Figure 2 shows the settings I used. Doing this removes a majority of the background color. You could also use the Eraser tool to remove other color remnants to finalize the video.
Figure 2. After Effects Color Keying controls, showing the settings for the demo
Export this video as an FLV file. If you installed Flash 8, you'll see an Export to FLV option in After Effects. Select File > Export > Macromedia Flash Video (FLV), name the file Sample.flv, and click Save. This opens the Flash Video Encoder settings dialog box, in which you can change your FLV settings.
If you don't have After Effects, or you have another video editing application that doesn't support the FLV format, then export to another video format that supports alpha channels and use the Flash 8 Video Encoder to convert your file to the FLV format. Keep in mind that using the actual Flash Video Encoder has a few benefits over the After Effects FLV Encoder option. For example, you can add cue points to your video before encoding. Using this feature can save you lots of time and effort later on. Flash 8 Video Encoder also supports the crop and trim options.
To encode the alpha channel, click the Show Advanced Settings button and click the Encode Alpha Channel option (see Figure 3). You can change the other settings as required. However, other than the Encode Alpha Channel feature, the default settings are fine for this example. After you select your settings, click OK. The FLV file will be saved to the location you chose earlier.
Figure 3. FLV Export panel (top) showing the Encode Alpha Channel option (bottom)
Now that you have your new alpha video file, import it into Flash. The new video import wizard in Flash 8 uses a four-step process to import your videos (File > Import Video):
I have created a simple demo that uses four pieces of alpha video. It shows how you can use multiple videos at once, change backgrounds at runtime, and yet use the interface controls under the video files. It also uses some of the new Flash 8 video features such as the FLVPlayback component. Play the demo below; the source is available as part of the ZIP sample file that accompanies this article.
Play the demo: Alpha Video in Action
The possibilities with using alpha video are endless. You can dynamically change the background of a video, integrate video into traditional animation and games, or overlay an interactive guide over your content with no loss of quality. (See the Sample.fla file found in the ZIP sample for an example). Bear in mind that the use of video comes with a steep bandwidth penalty—evaluate your target market before including video in your commercial projects.
The scope of this article covers only the basics of alpha video. There is no dearth of resources available to you if you would like to probe further into this subject. Start with the following resources:
Get a free trial of dvMatte Pro After Effects Edition at dvgarage.com.
Wes Gorgichuk is a Flash developer with gskinner.com, an industry-leading Flash development company. Over the past five years he has worked in all aspects of multimedia, from designing to progamming and everything in between. But Flash has always been his passion. Walt Disney said it best: "It's kinda fun to do the impossible"—and it is, especially with Flash.