Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > Usability

This chapter is from the book

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

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

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

Additional Practice

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.

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020