May 00 QTToolkit
Volume Number: 16
Issue Number: 5
Column Tag: Programming
In and Out
by Tim Monroe
Using QuickTime's Movie Importers and Exporters
In the previous QuickTime Toolkit article, we looked at graphics importers and
exporters, which allow us to read still images from files, draw those images, and save
the images in new image formats. In this article, we're going to take a look at movie
importers and exporters, which allow us to convert various kinds of data to and from
the QuickTime movie format. A movie importer reads data and converts it into a
QuickTime movie, and a movie exporter writes QuickTime movie data in some other
format. For example, we can use a movie importer to read an AVI file and convert it
into the QuickTime movie format. At that point, we can display the movie in a window
and attach a movie controller to it, exactly as if the original data had been stored in the
QuickTime file format. Conversely, we can use a movie exporter to save QuickTime
movie data as an AVI file. Because movie importers and exporters allow us to change
the format of movie data, they are also called movie data exchange components.
Originally, movie importers and exporters were mainly intended to read and write
data stored in files that are not QuickTime files. We can, however, use movie data
exchange components for other purposes also. In particular, we can use movie
exporters to change the compression format or compression settings of a QuickTime
file. We can also use movie exporters to add hint tracks to a movie so that the movie
can be streamed over a network. In this case, the existing movie data isn't actually
being converted to some other format; rather, new tracks are being added to the movie
to enable the movie data to be efficiently broken up into packets that can be sent out
over a network.
In this article, we'll begin by considering how to export a movie under a new format.
We'll see how to do this in two ways, first allowing the user to select any available
export format and then restricting the export format to a particular format. Next we'll
investigate how to import non-movie files as movies. Finally, we'll learn how to use
movie progress functions, which the Movie Toolbox calls when an operation (such as
importing or exporting a movie) promises to take a significant amount of time.
Exporting Movies
To export a movie is to convert it into a new format or to change the movie data in some
other way. QuickTime provides a number of functions that we can use to export a
movie. By far the easiest to use is the ConvertMovieToFile function, whose declaration
(in Movies.h) looks essentially like this:
OSErr ConvertMovieToFile (
Movie
theMovie,
Track
onlyTrack,
FSSpec *
outputFile,
fileType,
[TOKEN:20307]Type
creator,
scriptTag,
short *
resID,
long
flags,
ComponentInstance
userComp);
Most of these parameters have pretty obvious uses: theMovie, of course, is the movie
we want to export, and outputFile points to a file system specification for the file we
want the converted movie data to be put into. The fileType and creator parameters are
the desired file type and file creator code of the destination file, and scriptTag is the
script into which the movie should be converted.
A few of these parameters are less obvious. The onlyTrack parameter specifies which
track in the source movie is to be converted; we'll always specify NULL for this
parameter to have ConvertMovieToFile convert all the tracks in the movie. The resID
parameter points to some storage that will receive the resource ID of the source
movie; we won't need this information, so once again we'll always pass NULL for this
parameter.
The userComp parameter specifies which movie export component should be used to
perform the data conversion. If we want the movie to be exported into a specific
format, we can open the appropriate movie export component and pass the component
instance in this parameter. On the other hand, if we want to display a dialog box that
allows the user to select the desired output format, then we can pass NULL in this
parameter. In that case, we should also specify 0 in the fileType parameter (since of
course we don't yet know what the file type of the output file should be).
Finally, the flags parameter specifies a 32-bit value whose bits encode information
governing how the movie conversion should proceed. Our first example of using
ConvertMovieToFile will use this line of code to configure the flags parameter:
myFlags = createMovieFileDeleteCurFile |
showUserSettingsDialog |
movieFileSpecValid |
movieToFileOnlyExport;
The createMovieFileDeleteCurFile flag tells ConvertMovieToFile to delete any existing
file specified by the outputFile parameter. The showUserSettingsDialog flag indicates
that ConvertMovieToFile should display a movie export dialog box, shown in Figure 1.
Figure 1. The movie export dialog box.
If the showUserSettingsDialog flag is set, then the movieFileSpecValid flag indicates
that the name specified in the name field of the file system specification pointed to by
the outputFile parameter should be the name initially displayed in the export dialog
box. Also, if showUserSettingsDialog is set, then the movieToFileOnlyExport flag
indicates that the user should be allowed to select only from among the output formats