Modifier Tracks

Track references and modifier tracks create dynamic relationships between tracks in a QuickTime movie. Track references describe the relationship between tracks; for example, one track’s output can be connected to an input of another track, or two tracks may be related as alternate versions, to be used in different languages. Track references are used to create modifier tracks, alternate tracks, and chapter lists, and to relate timecode tracks to segments of other tracks.

A modifier track does not present its data as a video or audio track normally does; instead it uses its data to modify the presentation of other tracks. For example, the output of a video track can used as the source of image data for a sprite track or effect track, or the output of a tween track can be used as the source of the volume setting of an audio track. This chapter discusses several special modifier track types, including:

This chapter assumes that you are familiar with QuickTime tracks in general and the QuickTime functions used to determine and change the display characteristics of movies and tracks.

Track References

Track references are a feature of QuickTime that allows you to relate a movie’s tracks to one another. The QuickTime track-reference mechanismsupports many-to-many relationships. That is, any movie track may contain one or more track references, and any track may be related to one or more other tracks in the movie.

Track references can be useful in a variety of ways. For example, track references can be used to relate timecode tracks to other movie tracks. Another use of track references is to associate one or more text tracks that contain subtitles with the appropriate audio track or tracks.

Track references are also used to create alternate tracks, as discussed in Working With Alternate Tracks.

Every movie track contains a list of its track references. Each track reference identifies another, related track. That related track is identified by its track identifier. The track reference itself contains information that allows you to classify the references by type. This type information is stored in an OSType data type. You are free to specify any type value you want. Note, however, that Apple has reserved all lowercase type values.

You may create as many track references as you want, and you may create more than one reference of a given type. Each track reference of a given type is assigned an index value. The index values start at 1 for each different reference type. QuickTime maintains these index values so that they always start at 1 and count by 1.

Functions That Manipulate Track References

The following functions help you work with track references:

  • The AddTrackReference function allows you to relate one track to another.

  • The DeleteTrackReference function removes that relationship.

  • The SetTrackReference and GetTrackReference functions allow you to modify an existing track reference so that it identifies a different track.

  • The GetNextTrackReferenceType and GetTrackReferenceCount functions allow you to scan all of a track’s track references.

Creating Modifier Tracks

Modifier tracks are used to modify other tracks. Redirecting the output of a modifier track to the input of another track lets you create a wide variety of effects, such as panning audio or presenting video data as a sprite.

Any QuickTime track can be made into a modifier track. For example, you can use the output of a video track as a sprite’s image source, or the output of two video tracks as inputs to a transition effect in an effect track.

To create a modifier track, you need to use track references and input maps. A track reference lets you specify which track receives a modifier track’s output. An input map specifies the part or parts of the receiving track to be modified by the output of the modifier track. For example, the output of a tween track might modify a sound track’s volume, balance, or both.

Kinds of Modifier Tracks

A modifier track does not present any data; instead, it sends data to another track that uses that information to modify how it presents its own data. Any track can be either a sender or a presenter, but not both. For example, instead of simply playing video, a video track can send its image data to a sprite track. The sprite track then uses that video data to replace the image of one of its sprites. When the movie is played, the video track appears as a sprite.

Another use of modifier tracks is to store a series of sound volume levels, which is what occurs when you work with a tween track. These sound levels can be sent to a sound track as it plays, to dynamically adjust the volume. A similar use of modifier tracks is to store location and size information. This data can be sent to a video track to cause it to move and resize as it plays.

Because a modifier track can send its data to more than one track, you can easily synchronize actions between multiple tracks. For example, a single modifier track containing matrices as its samples can make two separate video tracks follow the same path.

Limitations of Spatial Modifier Tracks

A modifier track may cause a track to move outside of its original boundary regions. This may present problems, since applications do not expect the dimensions or location of a QuickTime movie to change over time.

To ensure that a movie maintains a constant location and size, QuickTime limits the area in which a spatially modified track can be displayed. A movie’s “natural” shape is defined by the region returned by GetMovieBoundsRgn. QuickTime clips all spatially modified tracks against the region returned by GetMovieBoundsRgn. This means that a track can move outside of its initial boundary regions, but it cannot move beyond the combined initial boundary regions of all tracks in the movie. Areas uncovered by a moving track are handled in the same way as areas uncovered by tracks with empty edits.

If a track has to move through a larger area than that defined by the movie’s boundary region, the movie’s boundary region can be enlarged to any desired size by creating a spatial track (such as a video track) of the desired size but with no data. As long as the track is enabled, it contributes to the boundary regions of the movie.

Media Handler Support

The video, base, and tween media handlers can send the data they receive to other tracks. The text media handler can also send data, but none of the track media handlers can currently receive it. The sound, music, and 3D media handlers do not support sending their data to other tracks.

Not all media handlers support all input types. Media handlers can decide which input types to support. Table 5-1 lists the input types supported by each Apple-supplied media handler.

Table 5-1  Input types supported by Apple-supplied media handlers

Input type

Video

Text

Sound

MPEG

Music

Sprite

Timecode

3D

Matrix

X

X

X

X

X

X

Graphics mode

X

X

X

X

X

X

Clip

X

X

X

X

X

X

Volume

X

X

X

 

Balance

X

X

X

 

Sprite image

X

X

3D sound

X

X

Creating Movies With Modifier Tracks

To create a movie with modifier tracks, first you create a movie with all the desired tracks, then you create the modifier track. To link the modifier track to the track that it modifies, use the AddTrackReference function shown in Listing 5-1.

Listing 5-1  Linking a modifier track to the track it modifies

long addedIndex;
AddTrackReference   (aVideoTrack,
                     aModifierTrack,
                     kTrackModifierReference,
                     &addedIndex);

The reference doesn’t completely describe the modifier track’s relationship to the track it modifies. Instead, the reference simply tells the modifier track to send its data to the specified track. The receiving track doesn’t know what it should do with that data. A single track may also be receiving data from more than one modifier track. You have to update the media input map of the receiving track to specify how the data is to be interpreted.

Manipulating Media Input Maps

Each track has particular attributes such as size, position, and volume associated with it. The media input map of that track describes where the variable parameters are stored so that modifier tracks know where to send their data. When a track is copied, its input map is also copied. CopyTrackSettings also transfers the media input map.

QuickTime provides two functions you can use to maintain media input maps:

To describe how each modifier input should be used, each track’s media has an input map. The media’s input map describes how the data being sent to each input of a track should be interpreted by the receiving track. After creating the reference, it is necessary to update the receiving track’s media input map. When AddTrackReference is called, it returns the index of the reference added. That index is the index of the input that needs to be described in the media input map. If the modifier track created above contains regions to change the shape of the video track, the code shown in Listing 5-2 updates the input map appropriately.

Listing 5-2  Updating the input map

QTAtomContainer inputMap;
QTAtom inputAtom;
OSType inputType;
Media aVideoMedia = GetTrackMedia(aVideoTrack);
GetMediaInputMap (aVideoMedia, &inputMap);
QTInsertChild(
         inputMap, kParentAtomIsContainer,
         kTrackModifierInput,
         addedIndex,
         0,
         0,
         nil,
         &inputAtom);
inputType = kTrackModifierTypeClip;
QTInsertChild (
         inputMap,
         inputAtom,
         kTrackModifierType,
         1,
         0,
         sizeof(inputType),
         &inputType,
         nil);
SetMediaInputMap(aVideoMedia, inputMap);
QTDisposeAtomContainer(inputMap);

The media input map allows you to store additional information for each input. In the preceding example, only the type of the input is specified. In other types of references, you may need to specify additional data.

When a modifier track is sending an empty track edit, or is disabled or deleted, all receiving tracks are notified that the track input is inactive. When an input becomes inactive, it is reset to its default value. For example, if a track is receiving data from a clip modifier track and that input becomes inactive, the shape of the track reverts to the shape it would have if there were no clip modifier track.

Working With Alternate Tracks

QuickTime lets you define alternate tracks in a movie. You can use alternate tracks to support multiple languages or to present different levels of visual quality in the movie. You collect alternate tracks into groups. Alternate track groups are collections of tracks that represent some conceptual data but are appropriate for use in different play environments. For example, you might have some 4-bit data in one track and some 8-bit data in another. Working with alternate tracks allows you to set up alternatives from which QuickTime can choose.

QuickTime selects one track from each alternate group when it plays the movie. For example, you could create a movie that has three separate audio tracks: one in English, one in French, and one in Spanish. You would collect these audio tracks into an alternate group. When the user plays the movie, QuickTime selects the track from this group that corresponds to the current language setting for the movie.

Similarly, you can use alternate tracks to store data of different quality. When the user plays the movie, QuickTime selects the track that best suits the capabilities of the user’s computer on which the movie is being played. In this manner, you can create a single movie that can accommodate the playback characteristics of a number of different computer configurations.

QuickTime allows you to store quality information for media structures that are assigned to either sound or video tracks. For all tracks, QuickTime uses bits 6 and 7 of the quality setting. These bits encode a relative quality value. These values range from 0 to 3. You can use higher quality values to indicate larger sample sizes. For example, consider a movie that has two sound tracks that are alternates for each other: one contains 8-bit sound and the other contains 16-bit sound. You could assign a quality value of mediaQualityNormal to the 8-bit media and a value of mediaQualityBetter to the 16-bit media. QuickTime would play the 16-bit media only if the user’s configuration could handle 16-bit sound. Otherwise, QuickTime would use the 8-bit media. The sound media handler determines the sample size for each sound media for QuickTime by examining the media’s sound description structure.

In addition, QuickTime also uses bits 0 through 5 (the low-order bits) of the quality setting. You use these bits to indicate the pixel depths at which the media should be played. Each bit corresponds to a single depth value, ranging from 1-bit pixels to 32-bit pixels. You may use these bits to control the playback of both video and sound tracks.

As an example, consider a movie that contains three video tracks with the following characteristics:

Track

Characterics

A

1-bit video data, no compression

B

Compressed using the Apple Video Compressor

C

Compressed using the Joint Photographic Experts Group (JPEG) compressor

You could assign the following quality values to these track’s media structures:

Track

Quality value

A

MediaQualityDraft + 1-bit depth + 2-bit depth (quality value is 0x0003: 0x0000 + 0x0003)

B

MediaQualityNormal + 4-bit depth + 8-bit depth + 16-bit depth + 32-bit depth (quality value is 0x007C: 0x0040 + 0x003C)

C

MediaQualityBetter + 4-bit depth + 8-bit depth + 16-bit depth + 32-bit depth (quality value is 0x00BC: 0x0080 + 0x003C)

QuickTime would always use Track A when playing the movie on 1-bit and 2-bit displays. At the other pixel depths, the video media handler determines which track to use by examining the availability and performance of the specified decompressors. If the JPEG decompressor can play back at full frame rate, QuickTime would use Track C. Otherwise, QuickTime uses Track B. The video media handler determines the compressor that is appropriate for each media by examining the media’s image description structure.

You set a movie’s language by calling the SetMovieLanguage function.

To establish alternate groups of tracks, you can use the SetTrackAlternate and GetTrackAlternate functions.

You can work with the language and quality characteristics of media by calling the GetMediaLanguage, SetMediaLanguage, GetMediaQuality, and SetMediaQuality functions.

By default, QuickTime automatically selects the appropriate tracks to play according to a movie’s quality and language settings, as well as the capabilities of the user’s computer. Whenever your application calls theSetMovieGWorld, SetMovieBox, UpdateMovie, or SetMovieMatrix function, QuickTime checks each alternate group for an appropriate track. However, you can control this selection process. Use the SetAutoTrackAlternatesEnabled function to enable or disable automatic track selection. The SelectMovieAlternates function instructs QuickTime to select appropriate tracks immediately. If no tracks in an alternate track group are enabled, then QuickTime does not activate any track from that group during automatic track selection.