Keying in After Effects
The best way to create transparent video for use in Flash projects is with Adobe After Effects. There are two reasons for this: First, After Effects offers advanced tools for masking, keying, and compositing. Second, you can easily access technology for converting video layers into Flash Video files with embedded alpha channels. Let’s explore the process with three sample compositions.
Included with After Effects is a powerful chroma key plug-in called Keylight. The technology used in Keylight uses a core algorithm written by the Computer Film Company. This technology has been used on numerous feature films including Harry Potter, Mission Impossible, and Sweeney Todd. Keylight has won the Academy Award for Technical Excellence and is a one-stop-shop for keying, despill, and color correction.
When you apply Keylight to a footage layer, you choose a color to key out. The effect then performs two tasks. First, it erases all the pixels that match the color. Second, it removes that color spill from other pixels. So if you select green, it will remove the backdrop and greatly reduce any green reflections on the foreground. Keylight is relatively easy to use (once you understand its options). It is also quite adept at properly keying reflections, semitransparent areas, and hair.
The Keylight plug-in can be a bit intimidating because it has nearly 60 parameters. The good news is that there are only a few main controls and the rest are just used for fine-tuning. Let’s start with some basic material that needs to be keyed.
- Copy the Chapter_04 Project Files folder from the DVD to a local hard drive. Open the file Chapter_04.aep from the Chapter_04 Project Files folder. This project file contains all the elements you will use for this chapter.
- In the Project panel, double-click the composition 01_Keying_Start to load it. Four clips are loaded into a Timeline. This composition uses non-square pixels, which will not work well in Flash. So, you’ll need to modify the composition’s settings.
Choose Composition > Composition Settings. From the Preset list choose HDV/HDTV 720 29.97 to switch to a square Pixel Aspect Ratio. Click OK. After Effects changes the composition size and automatically adjusts the clips to display properly.
- Choose Edit > Select All to select the four clips.
- Choose Effect > Keying > Keylight to apply the Keylight plug-in. Nothing appears to happen.
At the top of the Effect Controls panel click the drop-down menu and choose the topmost layer called 01_Keying_Start • Cell_Phone2.mov.
- Move the Current Time Indicator to the start of the composition by pressing the Home key. You are now ready to start the keying process.
Pulling an initial key
Keying is often a multistep process. You will find yourself finessing and refining to get the best results. However, the most dramatic change starts with a single click. When using Keylight, you’ll first choose the Screen Colour you’d like to remove (yes, the plug-in is British). The Screen Colour is the color you want removed from the background that Keylight will also despill from the rest of the scene.
Click the eyedropper next to Screen Colour to activate the selection eyedropper. Click just over the shoulder of the subject. You want to click close to the person to remove the green areas closest to the subject.
At first glance, the key looks “perfect.” But it’s not. Close examination will reveal that the image has extra transparency and some spill that needs to be corrected.
Click the drop-down menu next to View and switch to Screen Matte. This lets you see the grayscale matte that Keylight uses to create transparency.
The matte indicates transparent areas with black, opaque areas with white, and partially transparent areas with gray. Close examination of the matte indicates that the background has not been completely removed and that the shirt is showing undesirable amounts of transparency.
- Increase the Screen Gain parameter until the background is a clean black plate. For this first shot, a value of 110.0 works well. Some users alternately use the Clip Black slider discussed in the next section for similar results.
- Change the Screen Pre-blur to a value of 1.0 to slightly soften the edges of the generated matte. Avoid using a high value or halos will occur.
Cleaning up the matte
For a believable key, it’s best to have some gray pixels around the edge of the subject (so hairs and other semitransparent elements can blend into the background). However, the background should be solid black, and the foreground should be solid white. Currently, the background is in good shape, but the foreground could use some work.
Click the disclosure triangle next to Screen Matte to reveal several controls that you can use to fix matte problems.
Use one or more of the following sliders to refine the mask:
- Clip Black. Makes the blacks in the matte darker.
- Clip White. Makes the white areas in the matte whiter. Be careful with the Clip Black and Clip White controls so you don’t overdo it and ruin the edges of your foreground.
- Clip Rollback. Allows you to undo clipping and bring the edges back.
- Screen Shrink/Grow. Contracts or expands the matte.
- Screen Softness. Softens the generated matte.
- Screen Despot White. Removes white specks that are inside a generally black background.
- Screen Despot Black. Removes black specks that are inside a generally white foreground.
Lower Clip White to 85.0 to remove most of the “holes” in the matte.
- Adjust the Clip Rollback to 5.0 to restore edge detail and set the Screen Softness to 1.0 to remove fringe at the edges.
- Adjust Screen Despot Black to 5.0. You may need to resize the Effect Controls panel to see the full name. Click in the area between the Effect Controls panel and the Composition panel, and then drag to resize.
Click the View drop-down menu and choose Final Result to see your keyed footage.
After you’ve keyed the background, you’ll usually need to adjust the foreground colors so they properly match the colors of your new background. Fortunately, Keylight offers two sets of controls to fix these issues.
Foreground Colour Correction. Affects the majority of the person or object left behind after Keylight has removed the background.
Edge Colour Correction. Modifies a thin band of pixels running around the person or object. This is where the majority of color spill occurs from the background reflected on the subject and is a critical area to tweak when you are trying to make a believable composite.
- From the Project panel, drag the file Rooftop.tif to the bottommost position in your active composition. You’ll use this outdoor scene to adjust the colors of the footage to match.
- Reselect the top layer and in the Effect Controls panel, click the disclosure triangle next to Foreground Colour Correction. Select the Enable Colour Correction check box. Increase the Saturation slider to 115 to boost the color in the foreground.
- Adjust the Contrast and Brightness to match the foreground subject to the background plate. For this image, try a Contrast setting of 4.0 and a Brightness setting of –5.0.
- Click the disclosure triangle next to the Colour Balance Wheel. This allows you to adjust the white balance of the image and tint the foreground to better match the color temperature of the background.
Slowly drag the x of the wheel to the left. Experiment with different positions until the color matches well.
The Edge Hardness and Edge Softness parameters are also useful. Edge Hardness controls how much the edge color correction merges into main foreground color correction, whereas Edge Softness blurs the edges.
- Click the disclosure triangle next to Edge Colour Correction. Select the Enable Edge Colour Correction check box. Set Edge Grow to 10.0, Saturation to 80.0, and Brightness to -10.0 to reduce the richness of color at the edges (the results will be subtle). Set Edge Colour Suppression to Suppress Green.
Open the Colour Balancing area and set Saturation to -2.0 to further remove color from the edges.
Adjusting edge crop
Sometimes your image will need a slight crop or reposition due to its edges. It’s essential that you carefully examine the edges of the image when keying to look for undesired transparency or black fringe. The footage layer you are working with has both.
Let’s start with the stray transparency at the bottom of the frame. You need to nudge the layer down slightly to hide the soft bottom edge.
Select the layer Cell_Phone2.mov in the Timeline.
Press P to access the Position property. Set the Y value to 400.0 to reposition the footage in the Composition panel. For best results, type the number into the entry field. A decimal point value often results from dragging, which can lead to subpixel resampling and image softness.
The bottom edge is fixed, and the composition of the shot looks good. Close examination reveals a black edge along the top of the frame.
- In the Effect Controls panel, scroll to the bottom to see all the controls.
- Click the disclosure triangle next to Source Crops. Change the X Method and Y Method to Repeat the Edge Color. This removes most of the fringe.
Change the Top crop to 99.0. The edge is fairly clean, but a small color shift exists because the top corner of the matte has a little hot spot left.
Scroll up in the Effect Controls panel and enter a value of 3.0 for the Clip Black property to clean up the matte further and to produce a great edge with a smooth transition.
Your key is now complete. Three more shots are in the current Timeline with which you can practice. Each offers slightly different challenges including wispy hair and color spill. Use the techniques you’ve learned so far and practice keying these additional shots. When you are ready, continue with the lesson.
Sometimes you’ll need to combine masks to improve the quality of your keys in After Effects. This might be because the chroma key background is not big enough to fill the frame or because you have color spill or reflections. Let’s try keying a shot that needs a little extra work.
Adding a garbage matte
Sometimes areas of footage just need to be cropped before you even start the keying process. This is generally referred to as using a garbage matte and allows for areas to be masked.
- In the Project panel, double-click the composition 02_Masking_Start to load it. This composition contains one HD clip and is set to use square pixels. Notice that the background does not fill the entire screen.
- Select the layer Camera_Man.mov in the Timeline.
Double-click the Rectangle tool in the toolbar to add a rectangular mask to the footage. A new rectangular mask is added to the footage layer, and the Timeline expands to show Mask 1.
With layer 1 selected, press Command+T (Ctrl+T) to transform the mask. Control handles appear on the mask to control its size.
Drag the left and right edges in toward the center of the window to crop the black area from the video frame.
- Press Return (Enter) to apply the transformation. The footage now has the nonkeyable areas masked off with a garbage matte.
Perform the initial key by choosing Effect > Keying > Keylight. Using the techniques you learned earlier in this chapter, perform an initial key and clean up the matte using the Screen Matte settings. Be sure to crop a few pixels off the top of the frame as well. Also, set both X and Y Methods of Source Crop to Repeat.
Limiting the key with a mask
Keylight will sometimes remove more from the footage than you want. In this particular shot, you’ll notice that the lens of the camera is reflecting green (which lenses naturally do even when they are not placed near a green screen). This is causing the camera to show partial transparency. Fortunately, a mask can also be used here to limit Keylight’s reach.
Make sure layer 1 is selected and that Keylight’s controls have View set to Final Result. Closely examine the camera lens to see the unwanted transparency.
Click and hold on the Rectangle tool in the toolbar to reveal the other shapes available.
- Choose the Ellipse tool. Double-click the Ellipse tool to add an elliptical mask to the footage layer. The two masks combine to create a hybrid shape, which is not desired and can be easily fixed.
In the Timeline, make sure Mask 2 is selected, and then change its mode to None so the mask does not hide any parts of the footage.
- Press Command+T (Ctrl+T) to transform the mask.
Adjust the corners and position of the mask so it covers the front of the camera lens.
- Press Return (Enter) to apply the transformation. The mask can now be transformed over time with keyframes to follow the moving footage.
Click the triangle next to Mask 2 to reveal its keyframeable properties. Click the stopwatch next to Mask Path to enable keyframes for the shape and position of the mask.
- Move the Current Time Indicator forward to 1:00. The mask no longer covers the front of the camera. Press Command+T (Ctrl+T) to move and size the mask to cover the front of the lens.
Press Return (Enter) to store the transformation; a new keyframe is added.
- Move the Current Time Indicator to 2:00 and repeat the mask move and sizing.
- Repeat the mask movement and positioning every second in the Timeline. You should now have a keyframe for the Mask Path at each second in the Timeline. Now check to see if more keyframes are needed.
Press the Home key to return to the start of the composition and press the spacebar to watch the footage play slowly. Watch closely to see where the mask needs additional keyframes to ensure the lens reflection is covered.
The following points may need additional keyframes added to refine the mask. These times are approximations and may vary slightly depending on the initial shapes you created.
In the Effect Controls panel, click the disclosure triangle next to Keylight’s Inside Mask property. Set the Inside Mask drop-down menu to Mask 2. Adjust the Inside Mask Softness to a value of 1.0
- Check the effect by clicking the RAM Preview button in the Preview panel. Make sure the Resolution is set to Full Quality to properly judge the accuracy of the key and mask.
Exporting with transparency to Flash
Now that the footage layer is properly keyed, it is ready to export to Flash. While Flash supports three different codecs for video (Spark, On2, and H.264), only On2 VP6 supports the use of an alpha channel. Fortunately, After Effects makes this an easy export.
The video you want to export has lots of empty space, so you can nest this to create a smaller frame size.
In the Project panel, select the composition 02_Masking_End. Drag the composition onto the Create a New Composition button at the bottom of the Project panel. This creates a new composition that nests the original inside of it and also matches the size and duration of the original.
- Double-click the new composition called 02_Masking_End 2 to open it.
- Choose Composition > Composition Settings to modify the file.
- In the Composition Settings dialog, rename the composition Camera Man with Alpha. From the Preset list choose Custom. You will make a smaller-sized composition to size the video for Web use. Enter a Width of 250 pixels and a Height of 340 pixels. Be sure the Pixel Aspect Ratio is set to Square Pixels.
- Click OK to change the composition settings. When you reduce the frame size the resulting video file will load faster.
- Select layer 1 in the Timeline. Press P for position.
- Hold down the Shift key and press S for scale. Change the Scale to 50% for both the width and height.
Drag the position slider to position the video within the new comp. A value of 217.0 and 175.0 should work well.
- In the Preview panel, click the RAM Preview button to review your animation. Watch the animation through to make sure the video is not cropped at any point.
- Choose Composition > Add to Render Queue. The Render Queue controls how animations are processed and written to disk. Click the Best Settings text next to Render Settings to customize Output.
Because the output of Flash Video is intended for Web use, you can specify a lower frame rate. Select Use this frame rate and set its value to 15.
- To ensure that the entire animation renders, set the Time Span to Length of Comp. Click OK to store the Render Settings.
In the Render Queue click the Lossless Output Module text label to open the Output Module Settings window. Change Format to FLV. You now need to specify options for the format. Click the Format Options button.
- From the Preset list choose FLV – Same as Source (Flash 8 and Higher) to match the output size to the composition size. Deselect the Export Audio check box because there is no audio for this composition. Choose the On2 VP6 codec.
- In the Basic Video Settings area, select the Encode Alpha Channel check box to include transparency with the exported file.
- In the Advanced Settings area click the Quality list and choose Best for the highest quality (yet slowest) encode.
- Lower the data rate to 1000 kbps in the bitrate settings section. and then click OK to store the Format Options. Click OK to store the Output Module Settings.
- Click the filename next to Output To and specify the Chapter_04 Project Files folder that you copied at the start of the lesson.
- In the Render Queue click Render to create the file. The resulting file is now ready to use in a Flash project. The transparency is embedded into the file.
Using Transparent Video in Flash
Once your Flash video file is rendered, you can import it into Flash. The import process is quite simple as it is treated like any other footage item. You’ll learn more about Flash video options in Chapter 12, “Professional Encoding of Flash Video.”
- Launch Flash Professional. In the Welcome screen, click the Flash File (ActionScript 3.0).
In the Properties panel, click the Edit button. Set the document to 400 px × 400 px at 30 fps and click OK.
- With the Rectangle Tool, draw a rectangle to fill the canvas.
Click the Fill Color and choose the Black to Blue gradient.
- Add a new layer in the Timeline and name it cameraman.
Choose File > Import to Stage.
- Navigate to the FLV file you just rendered and click Import. The Import Video window opens.
- Choose Embed FLV in SWF and play in timeline. Click Continue.
A second window appears, the default options are okay for this example. Click Continue then click Finish.
- Position the video on the Stage using the Selection tool.
- Select the bottom layer in the Timeline. Move the playhead to frame 300.
- Right-click in the Timeline and choose Insert Frame to extend the background layer.
- Choose File > Publish Preview > Default to test the file. Close Flash (there is no need to save your test file).
If you’d like some additional keying practice, we’ve included one more task. You can open the file 03_Composite_Start to use the techniques you’ve learned so far as well as to experiment with new techniques. Gain confidence by exploring the footage and composition. You can compare your progress with the composition 03_Composite_End.
- Size the composition using a smaller size (640 × 360).
- Use square pixels for output to Flash.
- Perform a clean key of the TV_Shot.mov layer.
- Composite the Screen_Content.mov layer below the television. Use Position and Scale properties to resize and accurately place the layer in the right position.
- Use the Fast Blur effect to defocus the Screen_Content.mov layer.
- Export the composition as a layered file for Flash by choosing File > Export > Adobe Flash Professional (XFL).
- Import the XFL file into Flash Professional and explore the layered file.