Jun 00 QTToolkit
Volume Number: 16
Issue Number: 6
Column Tag: QuickTime Toolkit
Making Movies
by Tim Monroe
Creating QuickTime Movie Files
So far in this series of articles on programming QuickTime, we've learned how to open
movie files and allow the user to interact with the movies in those files. We've learned
how to perform some basic operations on movies, such as editing them and exporting
them under new formats. We've also learned how to open and display image files and to
perform some simple transformations on those images. And, for good measure, we've
managed to do everything in a fully cross-platform manner, so that our applications
run both under the Macintosh operating system and under Windows, with exactly the
same features.
Now it's time to take an important step forward in our journey through QuickTime: it's
time to learn how to create QuickTime movie files. Even though QuickTime supports a
vast array of types of media (audio, video, text, sprite animation, vector image,
virtual reality, and so forth), it expects that all of the media data and the information
describing that data will be stored in a specific format, called the QuickTime movie file
format. This means that once we learn the basic sequence of operations required to
create files that adhere to this format, we can fairly easily apply that knowledge to
create files containing any of these types of media data. For the moment, we're going to
restrict our attention to creating a QuickTime movie file with a single video track. But
the techniques we learn here will come into play over and over again in the future
when we want to create movie files that contain sound data, text, music, sprites, and
other types of media data.
Happily, the Movie Toolbox provides a set of high-level programming interfaces that
we can use to create movie files without having to know very much about the actual
details of the QuickTime movie file format. We need to know some of those details,
however, so we'll begin by surveying the structure of QuickTime movies and
QuickTime movie files. Then we'll be ready to create movie files that exhibit that
structure.
The Structure of QuickTime Movies
What exactly is a QuickTime movie? There are really two answers to this question. So
far in this series, we've been concerned primarily with QuickTime movies as they
exist in memory. That is to say, we've been working with items of type Movie that we
can play, edit, attach movie controllers to, and so forth. We typically obtain these
movies by opening QuickTime movie files, which exist on disk (or some other storage
medium). The movie file contains the audio and video data that is presented to the user
when a movie is being played, as well as other information (called metadata) that
describes how that audio and video data is organized and synchronized. Of course,
QuickTime isn't limited to playing audio and video data, so we'll need a more general
term to refer to the movie data contained in the movie file; let's call it media data.
As a rough preliminary characterization, then, we can say that a QuickTime movie file
is a file that contains the movie's media data and the associated metadata. (As we'll see
later, a movie file might not actually contain the media data, but only references to the
media data. For the moment, however, we'll ignore this possibility.) A QuickTime
movie, on the other hand, is a structure that contains information about the media data.
In effect, a QuickTime movie is just a bookkeeping device that contains the information
necessary to retrieve the media data from the QuickTime movie file and present it to
the user at the appropriate moment.
The exact structure of QuickTime movies is private. If you take a look into the header
file Movies.h, you'll see that a variable of type Movie is a pointer to a MovieRecord
structure, which is defined like this:
struct MovieRecord {
long
data[1];
};
All we can tell about the structure of a MovieRecord is that it contains at least 4 bytes
of data. We can operate on movies only by using the application programming
interfaces provided by the Movie Toolbox.
A movie consists of one or more tracks, plus some optional movie user data. A track
has a starting time and duration, and is associated with exactly one kind of media data.
So, for instance, a track might hold audio data or video data, but not both. A movie can
contain several tracks, each associated with a different kind of media data. Also, a
movie can contain several tracks that are associated with the same kind of media data.
For instance, a movie might have a video track and several audio tracks (perhaps in
different languages).
The structure of a track is also private. A variable of type Track is a pointer to a
TrackRecord structure, which is defined like this:
struct TrackRecord {
long
data[1];
};
A track contains a single media structure (or, more briefly, a media), which
references, but does not contain, the media data associated with the track. Once again,
as you've probably guessed, the structure of a media is private. A variable of type
Media is a pointer to a MediaRecord structure, which is defined like this:
struct MediaRecord{
long
data[1];
};
Figure 1 shows a standard way of depicting the structure of a QuickTime movie. As you
can see, this movie contains three tracks: two video tracks and one sound track.
Associated with a movie is a movie time coordinate system, which provides a means to
measure time in a movie. The basic unit of time measurement for a movie is the
movie's time unit, and the number of time units that elapse per second is the movie's
time scale. In the movie shown in Figure 1, the time scale is 600, so the time unit is
1/600 of a second. The sound track is scheduled to begin playing after 1 second has
elapsed in the movie, and video track 2 is scheduled to begin playing after about 1.5
seconds have elapsed. QuickTime requires that all tracks start at time 0, but the track
data can begin later in the movie; the empty space between the beginning of the movie
and the beginning of the track data is called the track offset.
Figure 1. The structure of a QuickTime movie.
Keep in mind that Figure 1 is intended to illustrate the logical structure of a
QuickTime movie, not the actual arrangement of bytes in memory. To repeat, the actual
structure of a QuickTime movie in memory is private. The only way to operate on
movies, tracks, or media is to use the APIs provided by the Movie Toolbox.
The Structure of QuickTime Movie Files
In contrast to the undocumented, private structure of QuickTime movies, the structure
of QuickTime movie files is completely public. This means, among other things, that
QuickTime movie files can be built on any operating system, whether or not the