ADC Home > Reference Library > Technical Q&As > QuickTime > Import & Export >

Programmatic configuration of a Movie Export Component


Q: I'm trying to export a movie directly to a Raw AVI file, I've tried using the built-in exporter in QuickTime but I seem to only get a Cinepak compressed AVI. I can use MovieExportDoUserDialog to put up the export dialog and change the settings, but I don't want to do that. Can I change the settings programmatically?

A: You can use QuickTime's built-in Movie to AVI File export component to export with several codecs. The default is Cinepak, but you can programmatically configure the component to use another compressor. Use MovieExportGetSettingsAsAtomContainer to retrieve the exporter settings as a QTAtomContainer, modify the spatial settings, then use MovieExportSetSettingsFromAtomContainer to configure the export component.

Listing 1 demonstrates setting up the AVI export component to programmatically use the Indeo 4 codec (kIndeo4CodecType), but you could just as easily choose Windows Raw codec (kWindowsRawCodecType) etc.


 OSErr SpitAVIMovie(const Movie inMovie, const FSSpecPtr inFile)
{
    ScriptCode           fileScript = smCurrentScript; // use smSystemScript on Windows
    MovieExportComponent movieExporter = NULL;
    QTAtomContainer      exportSettings = NULL;
    QTAtom               videAtom = 0,
                         sptlAtom = 0;
    SCSpatialSettings    spatialSetting;
    OSErr                err = noErr;

    // Open the AVI 'spit' component
    err = OpenADefaultComponent(MovieExportType, kQTFileTypeAVI, &movieExporter);
    if (err || !movieExporter) goto bail;

    // Get the default settings
    err = MovieExportGetSettingsAsAtomContainer(movieExporter, &exportSettings);
    if (err) goto bail;

    // Find the 'vide' Atom which contains the spatial settings
    videAtom = QTFindChildByID(exportSettings, kParentAtomIsContainer,
                               kQTSettingsVideo,
                               1, NULL);
    if (0 == videAtom) { err = cannotFindAtomErr; goto bail; }

    // Find the 'sptl' Atom - Spatial Settings
    sptlAtom = QTFindChildByID(exportSettings, videAtom,
                               scSpatialSettingsType,
                               1, NULL);
    if (0 == sptlAtom) { err = cannotFindAtomErr; goto bail; }

    // Set up our settings
    spatialSetting.codecType = EndianU32_NtoB(kIndeo4CodecType); // or kWindowsRawCodecType
    spatialSetting.codec = 0;
    spatialSetting.depth = EndianU16_NtoB(24);
    spatialSetting.spatialQuality = EndianU32_NtoB(codecLosslessQuality);

    // Change the atom data to reflect our settings
    err = QTSetAtomData(exportSettings, sptlAtom,
                        sizeof(spatialSetting),
                        &spatialSetting);
    if (err) goto bail;

    // Set the exporter settings
    err = MovieExportSetSettingsFromAtomContainer(movieExporter, exportSettings);
    if (err) goto bail;

    // Go ahead and spit
    err = ConvertMovieToFile(inMovie, NULL, inFile, 0, 0, fileScript, NULL, 0, movieExporter);

bail:
    if (movieExporter) CloseComponent(movieExporter);
    if (exportSettings) QTDisposeAtomContainer(exportSettings);

    return err;
}
                  

Listing 1. Export to AVI

References:

Movie Data Exchange Documentation

ConvertMovieToFile API

Dispatch 6 - Finding Movie Export Components


[Jun 18 2002]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.