02-05-2021



Settings for Expert Keying with Keylight 1.2 in After effects. For Video Production, green screen is an important part of producing media, it is used in video interviews and films. Understanding the basics of keying in after effects is a must for any digital media producer. Nov 17, 2020 After Effects offers many keying effects. The Color Difference Key effect creates transparency from opposite starting points by dividing an image into two mattes, Matte Partial A and Matte Partial B. Matte Partial B bases the transparency on the specified key color, and Matte Partial A bases transparency on areas of the image that don't contain.

Keying is an important part of AE if you are using items or characters on different backgrounds. You know the infamous green or blue screens. The reason green is used so often is that the human body has shades of red already in the skin–green is the opposite of red, so it’s a great background color for contrast. A vibrant green is easy to key, thus it’s also easy to extract and make transparent–this allows you to replace the screen with a different background.

In this next section let’s learn the following:

Built-in Keying Tools

After Effects offers many tools for keying that can be found inside the Effects and Presets Panel, you can also find them by going to Effect > Keying. Some of the keying tools that AE offers are:

  • Color Difference Key
  • Color Range
  • Keylight
  • Color Key

Plus many more depending on your version of After Effects.

Effects

Masking

It’s useful and more efficient to mask out unwanted areas of footage that you are not going to see. For example, if you have a dancer in front of a green screen, great! But if the footage was filmed from 45 feet away, and you can see various objects around the border of the green screen the dancer was filmed in front of, you’re going to want to mask out those areas to keep a solid selection in and around your focal point.

Just remember, the subject will move and you don’t want to have to consistently animate your mask, so try to maintain a decent amount of space around them. You want to just mask out the nonsense around the border of your footage. This will make keying much easier.

To create your mask, first select the layer you want to place the mask on, then select the Pen Tool from your toolbar. Draw out your mask directly on the layer. Your mask doesn’t have to be perfect the first time around–you can always go back and adjust the segment points.

Once you have completed the shape of your mask, the outside area will become transparent. This area will reveal the background color of your comp, so make sure your background is black for best results. You will want to scroll through your footage and make sure that no one moves beyond the borders of your mask or you will have to animate your mask’s shape as well.


Join Our Creative Community

Access the best video tips, design hacks, and deals straight to your inbox.

Removing Unwanted Background

After

Now that you have your area masked, you’ll want to remove the background. Select your layer and go to Effect > Keying > Color Key. Once you select this as your effect, the Control Panel will open up. Select the Eyedropper and click on an average green area to set the Key Color that will be removed.

Once you’ve clicked on this area, AE will start to cut out the green. To improve your final look, you will have to adjust the values for the Tolerance and Edge settings.

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.

Using Keylight

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.

Getting started

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.

  1. 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.
  2. 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.
  3. 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.

  4. Choose Edit > Select All to select the four clips.
  5. Choose Effect > Keying > Keylight to apply the Keylight plug-in. Nothing appears to happen.
  6. Install git on visual studio code. 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.

  7. 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.

  1. 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.

  2. 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.

  3. 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.
  4. 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.

  1. 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.
  2. Lower Clip White to 85.0 to remove most of the “holes” in the matte.

  3. 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.
  4. 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.
  5. Click the View drop-down menu and choose Final Result to see your keyed footage.

Correcting color

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

  6. 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.
  7. 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.

  1. Select the layer Cell_Phone2.mov in the Timeline.

  2. 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.

  3. In the Effect Controls panel, scroll to the bottom to see all the controls.
  4. 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.
  5. 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.

  6. 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.

Effects

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.

Using Masks

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.

  1. 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.
  2. Select the layer Camera_Man.mov in the Timeline.
  3. 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.

  4. With layer 1 selected, press Command+T (Ctrl+T) to transform the mask. Control handles appear on the mask to control its size.

  5. Drag the left and right edges in toward the center of the window to crop the black area from the video frame.

  6. Press Return (Enter) to apply the transformation. The footage now has the nonkeyable areas masked off with a garbage matte.
  7. 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

Keying In After Effects Cc

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.

  1. 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.

  2. Click and hold on the Rectangle tool in the toolbar to reveal the other shapes available.

  3. 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.
  4. 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.

  5. Press Command+T (Ctrl+T) to transform the mask.
  6. Adjust the corners and position of the mask so it covers the front of the camera lens.

  7. Press Return (Enter) to apply the transformation. The mask can now be transformed over time with keyframes to follow the moving footage.
  8. 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.

  9. 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.
  10. Press Return (Enter) to store the transformation; a new keyframe is added.

  11. Move the Current Time Indicator to 2:00 and repeat the mask move and sizing.
  12. 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.
  13. 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.

  14. 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.

    • 00;00;01;15
    • 00;00;02;15
    • 00;00;04;20
    • 00;00;05;10
    • 00;00;06;10
    • 00;00;06;20
    • 00;00;07;15
    • 00;00;09;15
  15. 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

  16. 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.

  1. 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.

  2. Double-click the new composition called 02_Masking_End 2 to open it.
  3. Choose Composition > Composition Settings to modify the file.
  4. 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.
  5. Click OK to change the composition settings. When you reduce the frame size the resulting video file will load faster.
  6. Select layer 1 in the Timeline. Press P for position.
  7. Hold down the Shift key and press S for scale. Change the Scale to 50% for both the width and height.
  8. Drag the position slider to position the video within the new comp. A value of 217.0 and 175.0 should work well.

  9. 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.
  10. 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.
  11. 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.

  12. To ensure that the entire animation renders, set the Time Span to Length of Comp. Click OK to store the Render Settings.
  13. 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.

  14. 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.
  15. In the Basic Video Settings area, select the Encode Alpha Channel check box to include transparency with the exported file.
  16. In the Advanced Settings area click the Quality list and choose Best for the highest quality (yet slowest) encode.
  17. 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.
  18. Click the filename next to Output To and specify the Chapter_04 Project Files folder that you copied at the start of the lesson.
  19. 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.”

  1. Launch Flash Professional. In the Welcome screen, click the Flash File (ActionScript 3.0).
  2. In the Properties panel, click the Edit button. Set the document to 400 px × 400 px at 30 fps and click OK.

  3. With the Rectangle Tool, draw a rectangle to fill the canvas.
  4. Click the Fill Color and choose the Black to Blue gradient.

  5. Add a new layer in the Timeline and name it cameraman.
  6. Choose File > Import to Stage.

  7. Navigate to the FLV file you just rendered and click Import. The Import Video window opens.
  8. Choose Embed FLV in SWF and play in timeline. Click Continue.
  9. A second window appears, the default options are okay for this example. Click Continue then click Finish.

  10. Position the video on the Stage using the Selection tool.
  11. Select the bottom layer in the Timeline. Move the playhead to frame 300.
  12. Right-click in the Timeline and choose Insert Frame to extend the background layer.
  13. Choose File > Publish Preview > Default to test the file. Close Flash (there is no need to save your test file).

Colour Keying In After Effects

Additional Practice

Chroma Keying In After Effects

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.