Captions for Video with Flash CS3 (Part Two)

In Captions for Video with Flash CS3 (Part One), we showed you how to add captions to a Flash video file using the Timed-Text XML standard. In this article, we’re going to look at another method of captioning: embedding the XML directly into the FLV file. In very simple terms, the XML document will contain the cue points for the captions. When one of those cue points is reached, the caption appears over the video.

There are actually four ways of adding cue points to an FLV. They are:

Manually add the cue points when the FLV is created in the Flash Video Encoder.

Add the cue points using the FLVPlayback component’s parameters.

Add them using the addASCuePoint() method in ActionScript.

Insert them through the use of an XML file.

The first two methods are the most problematic. Add a cue point using either method and it is hard wired into the FLV. If the timing is wrong or a change is required, your only option is to re-encode the FLV and manually add the cue points…again.

The last two methods are the most flexible. If a change is needed, it can quickly be done in the code or the XML document.

The embedding method is a bit different from the Timed-Text approach. You will be adding Event cue points to the video. When it comes to Flash video, there are two types of cue points that can be added: Navigation cue points and Event cue points. Navigation cue points navigate, seek, and are used to trigger ActionScript methods. When you create a Navigation cue point, Flash will insert a key frame at that point in the video. Event cue points are the most common. They tell Flash to do something—for example, toss up a caption—when they are encountered.

The XML used in this case is a lot different from the code in the previous article. Here’s the XML we will be using:

This is the syntax you must use. You are opening yourself up to a world of grief if you move outside of it. The first line is the XML declaration, and the second line tells Flash that anything between the FLVCoreCuePoint tags is to be used within the various cue points.

Each cue point must be enclosed between <CuePoint> tags. The <Time> tag is the start time for the cue point. It must be expressed in milliseconds. The next tag, <Type>, tells Flash the type of cue point to expect—in this case, an Event cue point—and the tag following it is the cue point’s name.

The rules regarding the naming of cue points have been set by Adobe and can’t be bent. The <Name> tag must be fl.video.caption.2.0, followed by a series of sequential numbers which guarantee the uniqueness of the name. In this exercise, the names are fl.video.caption.2.0.0, fl.video.caption.2.0.1, and so on.

The parameters also contain the styling data for the text appearing in the caption and the end time for the caption. The <endTime> element requires a different value from that used in the <Time> element. It’s expressed in seconds rather than milliseconds, and dictates the point at which the caption disappears from the screen. Using the XML example above, the caption will appear 240 milliseconds after the start of the video and end at the 4.1-second mark.

There are a couple of other cue points that need to be added. The easiest way of doing that is to simply copy and paste the entire CuePoint element and paste it in front of the </FLVCoreCuePoints> tag. From there you simply need to change the times and the text.

Embedding XML into an FLV

With the XML document in place, let’s look at how it gets embedded into the FLV.

Open the Adobe Flash CS3 Video encoder. Drag the video to be captioned into the queue window. Click the Settings button to open the Encoding Settings window.

Name the file. I called mine FinalHead. Click the Video tab to open the video settings. To encode this particular video, I used these values:

Video codec: ON2VP6

Max data rate: 300 kilobits per second

Frame rate: 15

Image 1. The video encoding settings are applied.

Click the Audio tab to open the audio settings. Reduce the audio data rate to 64 kbps (mono).

Click the Cue Points tab to open the Cue Points window.

When the Cue Points window opens, click the Browse button—it looks like a folder—to open the Load Cue Points File dialog box. Navigate to the XML file you will be using. Select it, and click the Open button.

When the dialog box closes, you will be returned to the Cue Points window. The Cue Points will appear.

Click on the first one and you will be taken to that point in the video. The parameters from the XML document will also appear.

Image 2. The Cue Points and their parameters from the XML document are imported, intact, into the FLV.

Click the OK button to return to the Render queue. Click the Start Queue button to encode the video. When it finishes, quit the Encoder.

Playing an FLV with Cue Points in Flash

The final step in the process is to create the Flash file. Here’s how:

Open a new ActionScript 3.0 document in Flash CS3 Professional. You are going to need to use both the new FLVPlayback and Captioning components. When the new document opens, immediately save it to the same folder as the FLV.

Add a new layer to the timeline. Name the new layer Captions and the first layer Player.

Select Window > Components to open the Components panel. Drag a copy of the FLVPlayback component into the Player layer, and a copy of the FLVCaptioning component to the Captions layer. By simply dropping the FLVCaptioning component onto the Flash stage, you have enabled the use of the captions in the FLV. The thing I adore about this is it allows me to work code-free.

Image 3. The components are added to the Flash stage.

The final step in the process is to hook the FLV file you created into the FLVPlayback component. Follow these steps:

Select the Playback component on the stage. Click once on the Parameters tab in the Property Inspector. Alternately, you could select the component and select Window > Component Inspector. (I prefer this method simply because I am lazy. All of the parameters are shown in a single window and and I don’t need to scroll.)

Double-click the Auto Play parameter and select false. This means the video doesn’t start playing as soon as it loads. The user will have to click the Play button.

Double-click the Skin parameter to open the Select Skin dialog box. Select the SkinUnderAllNoFullscreen.swf selection. This skin automatically adds the Captions button to the skin. Click OK to close the dialog box.

Image 4. The skin is selected and a Captions button is a part of the skin.

Double-click the Source Parameter to open the Content Path dialog box. Navigate to the FLV file. Select it and click Open. When you return to the Content Path dialog box, click OK to close it. You should see not only the FLV file in the parameters, but the Cue Points embedded into it will also appear in the Cue Points parameters.

Image 5. The FLV and the embedded Cue Points appear in the FLVPlayback component’s parameters.

Save the movie and test it by pressing Ctrl-Enter (PC) or Command-Return (Mac). I’ve created an example file so you can see it in action.

Conclusion

As can see from these two articles, Flash video is well on the road to accessibility. In this article we showed you how create the XML file that contains the cue points, how to embed them into an FLV file and then, through the addition of the FLVCaptioning component to the stage, enable the captions to appear in the video.

If you have been following this series you may be wondering which method is the best method. If you are passionate about web standards, then the Timed Text way is for you. If you aren’t, either method works. In the final analysis, your client doesn’t care how you got the captions to appear; he or she only cares that they are there.

Tom Green is a professor of Interactive Multimedia, through the School of Media Studies at Humber College in Toronto. He is also a speaker, and the author of six books, including two recent ones on Flash and Flash Video. An Adobe Community Expert and a Community MX partner, he believes the amount of fun we have in this business should be illegal.