Documentation Archive Developer
Search

ADC Home > Reference Library > Technical Q&As > QuickTime > Movie Basics >

Batch Exporting movie sound tracks with ConvertMovieToFile()


Q: I'm trying to batch export Movie sound tracks as AIFF files encoded with QDesign. ConvertMovieToFile() does this nicely, but I would like to configure the encoder only once for multiple files and not every time my application is run.

A: ConvertMovieToFile() can take a ComponentInstance as its last parameter. If you want a particular movie export component to perform the conversion (such as the AIFF "spit" component) you may pass an instance of that component here. This allows you to communicate directly with the component beforehand establishing any conversion parameters the user might want.

Here's how:

Open an instance of the export component, then use MovieExportDoUserDialog() to request the component to display its user dialog box. This provides an opportunity for the user to configure the component and will get the component to fill out the parameters fully and correctly. Because some encoders have complicated combinations of sample rates and output bit rates, it is a lot of work to do this by hand.

Once configured, call MovieExportGetSettingsAsAtomContainer() and save the resulting AtomContainer, perhaps in a configuration or preference file. You now have configuration information which can be used over and over again. See Listing 1.

When performing a batch mode operation simply open an instance of the Exporter component, call MovieExportSetSettingsFromAtomContainer() with the AtomContainer previously saved. The Export component will be configured as it was before avoiding any user interaction. You can then call ConvertMovieToFile() using the fully configured Export component as the last parameter. See Listing 2.

Once you're finished with the component be sure to close it by calling CloseComponent().


 Listing 1.

ComponentResult GetExportSettings(Movie inMovie, Track inTrack,
     QTAtomContainer *outSettings)
{
    Component c = 0;
    ComponentInstance theExporter = 0;
    ComponentDescription cd = { MovieExportType,
                                kQTFileTypeAIFF,
                                StandardCompressionSubTypeSound,
                                hasMovieExportUserInterface,
                                hasMovieExportUserInterface };
    ComponentResult err = invalidComponentID;
    Boolean ignore;

    c = FindNextComponent(0, &cd);
    if (c == 0) goto bail;

    err = OpenAComponent(c, &theExporter);
    if (err || theExporter == 0) goto bail;

    err = MovieExportDoUserDialog(theExporter, inMovie,
         inTrack, 0,
      GetTrackDuration(inTrack), &ignore);
    if (err) goto bail;

    err = MovieExportGetSettingsAsAtomContainer(theExporter,
         outSettings);

bail:
    if (theExporter)
        CloseComponent(theExporter);

    return err;
}

 Listing 2.

OSErr DoExport(Movie inMovie, Track inTrack, FSSpec inFile[],
     UInt16 inCount, QTAtomContainer *inSettings)
{
    Component c = 0;
    ComponentInstance theExporter = 0;
    ComponentDescription cd = { MovieExportType,
                                kQTFileTypeAIFF,
                                StandardCompressionSubTypeSound,
                                hasMovieExportUserInterface,
                                hasMovieExportUserInterface };
    OSErr err = invalidComponentID;

    c = FindNextComponent(0, &cd);
    if (c == 0) goto bail;

    err = OpenAComponent(c, &theExporter);
    if (err || theExporter == 0) goto bail;

    err = MovieExportSetSettingsFromAtomContainer(theExporter,
         *inSettings);
    if (err) goto bail;

    while (inCount && !err) {
        err = ConvertMovieToFile(inMovie,
                               inTrack,
                               &inFile[--inCount],
                               kQTFileTypeAIFF,
                               sigMoviePlayer,
                               smSystemScript,
                               NULL,
                               0,
                               theExporter);
    }

bail:
    if (theExporter)
        CloseComponent(theExporter);

    return err;
}

[Sep 05 2000]