Chapter 28. Getting Started with the Movie Library

This chapter explains how to begin developing a Movie Library application. It presents terminology and describes the steps involved in developing, compiling, and debugging a Movie Library application. It also explains how to work with movie and track properties.

Movie Library Basics

This section defines basic terms and explains fundamental concepts that you need to know in order to use the Movie Library, including the Movie Library programming model and movie file formats.

Definitions

The definitions in this section provide a foundation for working with the Movie Library.

A digital movie is a file that contains tracks of image and audio (optional) data.

A track represents a data stream. Each track can contain only one type of medium, either an image sequence or an audio soundtrack. Currently, a maximum of one image track and one audio track is allowed.

Just as motion picture film is actually a sequence of individual photographs, the image track of a movie file is actually a sequence of still images, such as illustrations, camera images, or computer graphics, contained within individual image frames of uniform height and width. Some movies have special image frames called keyframes that contain information for a block of frames that is treated as a single unit.

The audio track contains digitized audio (samples) of narration, music, sound effects, and so on, that are synchronized to the frames of the image track.

An image frame contains a single image, composed of individual pixels. An audio frame is composed of one audio sample for each audio channel.

The frame count of a movie is the total number of image frames in that movie. Image frames are numbered from zero to one less than the frame count.

Figure 28-1 is a conceptual illustration of somersault.mv, a movie with one image track, a stereo audio track, and 13 frames (only 10 are shown).

Figure 28-1. Typical Movie: somersault.mv


The frame rate of a movie refers to the number of image frames played per unit length of time. A typical frame rate is 15 frames per second (FPS), which means that each frame is displayed for 1/15 of a second.

Looping is the process of repeatedly playing a frame, a sequence of frames, or an entire movie. A movie loop is a useful display method for graphical sequences that cannot be rendered in real time or for any sequenced image data. When playing a movie, the movie loop can include the entire movie or a fragment of the movie, but you can only have one loop per movie. You cannot have a track loop. The Movie Library has three loop modes:

  • nonlooping (play once through)

  • looping (continuous play)

  • swinging (repeatedly playing forward then backward)

Movie Library Programming Model

The Movie Library programming model consists of:

  • movie instances, which are handles to movie files

  • tracks, which contain audio or images

  • parameter-value lists, which contain movie and track properties

A movie instance is a handle that allows you to read, write, edit, and play a movie file. It contains information about the different tracks (audio and image) in a movie and is identified by a movie ID similar in nature to a file descriptor. An application can create several movie instances at once.

Movie File Formats

The Movie Library provides a file-format-independent API and lets you convert movies from one format to another. Currently supported formats are the Silicon Graphics movie format and the Apple Computer QuickTime movie format.

Silicon Graphics Movie Formats

Silicon Graphics uses a proprietary movie file format that has evolved over time to the current 3.0 version. You can read movies that use previous versions (1.0 and 2.0) of the file format—for example, movies that were created using the prerelease alphas of the Movie Library or previous releases of Movie Maker—but the Movie Library writes only Silicon Graphics version 3.0 movie files.

The Silicon Graphics version 3. 0 movie format is a parameterized file format with data that is normally interleaved. It currently consists of a single image track and an optional audio track.

Apple Computer QuickTime File Format

See Chapter 31, “Using the Movie Library with QuickTime Movies,” for information on working with QuickTime movies and on using the optional Silicon Graphics QuickTime Compressor Library, which provides Movie Library support for both Apple Animation and Apple Video compression.

See Inside Macintosh: QuickTime for information about developing QuickTime applications, and see the QuickTime Starter Kit User's Guide for information on how to use the Apple QuickTime utilities on the Macintosh.

Deciding Which Format to Use

The destination system determines which movie format to choose when writing the final version of a movie file. Use the QuickTime format only if you require cross-platform compatibility between Silicon Graphics and Apple Macintosh computers.

Developing a Movie Library Application

This section provides a nutshell description of how to develop a Movie Library application, including compiling and debugging instructions.

A good way to get started with the Movie Library is to look at the sample programs in the /usr/people/4Dgifts/examples/dmedia/movie directory. They demonstrate creating, editing, playing, and getting information about movies. See Chapter 32, “Using the Movie Library Sample Programs,” for complete descriptions of the sample programs.

Outline for Developing a Movie Library Application

Follow these steps to develop a Movie Library application:

  1. Open an existing movie file by calling either mvOpenFile(), mvOpenMem(), or mvOpenFD() or create a new movie instance by calling mvCreateFile(), as described in Chapter 29, “File I/O and Editing Movies with the Movie Library.”

  2. Once you have a movie instance, you can find existing tracks, add tracks to the movie, and delete tracks from the movie. If, in step 1, you created a new movie rather than open an existing movie, you must add an image track to it if one does not already exist.

  3. Read and write images and audio from and to the movie tracks using the Movie Library file I/O functions, such as mvReadFrames() and mvInsertFrames() that are described in Chapter 29.

  4. Use the Movie Library editing functions to efficiently implement editing tasks such as deleting part of a movie by calling mvDeleteFrames(), and copying data from one movie to another by calling mvPasteFrames(). Editing is described in Chapter 29.

  5. To play a movie, configure a playback window and use mvBindWindow() to associate a movie with the playback window. You can play more than one movie simultaneously, in separate windows or in the same window. Playback is described in Chapter 30, “Playing Movies with the Movie Library.” You can't edit a movie that you have opened for playback, so write the file before attempting to play it.

  6. When you have finished with a movie, call mvClose() to destroy the movie instance.

Compiling and Linking a Movie Library Application

Movie Library applications must include the movie.h header file to obtain definitions for the library. When compiling your Movie Library application, follow these linking requirements in the order specified:

-lmovie -ldmedia -lcl -lawareaudio

where:

-lmovie 

links with the Movie Library (libmovie)

-ldmedia 

links with the DM Library (libdmedia), which provides parameter setting and ring buffering capabilities

-lcl 

links with the Compression Library, which provides compression capability

-lawareaudio 

links with the part of the Compression Library that provides Aware audio compression-decompression (codec) support. The part of the CL that provides Aware software codecs requires separate linking to accommodate end-user licensing. Currently, applications are required to link with this library even if it is not used, but licensing is optional for the end user.

If your application uses the Movie Library to play movies, you must add the following to the end of the link line:

-lgl -laudio -lX11 

where:

-lgl 

links with the IRIS GL

-laudio 

links with the Audio Library

-lX11 

links with the X11 library

Debugging a Movie Library Application

The Movie Library has two facilities designed to assist you in debugging your application:

  • a debugging version of the Movie Library, libmovie_d.a, which checks for improper usage of the Movie Library, such as out-of-bounds values and invalid parameters

  • environment variables that allow you to emulate certain types of failures such as I/O errors, without actually causing failures

Using the Debugging Version of the Movie Library

The debugging version of the Movie Library checks for violations by setting assertions that rigidly state the requirements for a parameter or value. One typical assertion, worded in standard English, is: “Check that the current frame number is within the bounds of the number of frames in the movie,” which is more precisely stated in the following assertion:

ASSERT( 0 <= frame < trackLength, "Frame number out of range")

To use the debugging version of the library, link with libmovie_d.a as follows:

-lmovie_d

and then run your program.

Your application will abort with an error message if it fails an assertion. The message explains the situation that caused the error, and by implication or by explicit description, suggests a corrective action.

When you have finished debugging your application, you should relink with the nondebugging library, libmovie.a, because the runtime checks imposed by the debugging library cause an undesirable performance and size overhead for a packaged application.

Emulating I/O Failures

When attempting to read data from a device such as a CD-ROM drive or over the network, two types of problems can occur:

  • lost connections—either the CD (or other storage medium) is missing or defective or, when reading data over the network, the remote host is unreachable

  • delays—either the seek time is too long or network delays are occurring

You can test how your application handles these types of I/O failures by setting the following environment variables to emulate failures without causing actual failures:

MVPLAYDBG_VIDREAD

simulates I/O errors when reading video

MVPLAYDBG_AUDREAD

simulates I/O errors when reading audio

MVPLAYDBG_VIDNFS

simulates delays when reading video

MVPLAYDBG_AUDNFS

simulates delays when reading audio


Setting and Getting Movie Properties

Movies have certain inherent properties that provide information about their contents. Global movie properties apply to a movie as a whole; track properties apply only to tracks. Tracks have general properties that apply to all types of tracks, and specific properties that depend on the track medium.

Movie and track properties are stored in parameters, some of which you can set, others of which are read-only, because they are computed by the Movie Library from available information. You can also define your own parameters to represent properties not provided by the Movie Library.

This section explains how to set and get movie and track parameters using the universal mvSetParams() and mvGetParams() routines; then it explains how to use the Movie Library convenience routines for setting and getting individual movie and track parameters and for setting up defaults.

Setting and Getting Movie and Track Parameters

The type MVid is used for both movies and for tracks so that universal set and get functions can work on both movies and tracks. The Movie Library also provides convenience routines for setting and getting movie parameters, described in “Setting and Getting Global Movie Properties”, and setting and getting track parameters, described in “Setting and Getting Track Properties”.

To set or change a group of parameters for a movie or track, make a parameter-value list containing the names of the parameters you want to set and the values you want them to have, then pass this list to mvSetParams(). Its function prototype is:

DMstatus mvSetParams ( MVid movieOrTrack, DMparams* params,
                       DMparams* returnParamsSetOrNull)

where:

movieOrTrack 

is the movie or the track whose parameters you want to set

params 

is a pointer to a parameter-value list that contains the parameters and settings you want

returnParamsSetOrNull 


is a pointer to a parameter-value list into which the Movie Library loads those parameters and values that it recognized and was able to set; if returnParamsSetOrNull is NULL, the Movie Library will not return such a list


Note: Some parameters cannot be changed and some are not recognized by the Movie Library; verify the results by checking the list returned in returnParamsSetOrNull.

To retrieve a list of the current parameters for a given movie or track, call mvGetParams(). Its function prototype is:

DMparams* mvGetParams ( MVid movieOrTrack )

mvGetParams() returns the parameter list associated with the given movie or track. For movies, the parameter list contains the movie property settings: file format, looping mode, and so on. For tracks, the parameter list contains information about the format of the data in the track.


Note: The application should not call dmParamsDestroy() on the returned parameter-value list. The Movie Library reuses the same structure for each call to mvGetParams().

See “Displaying Movie Parameters” in Chapter 32 for an example program called mvinfo that uses mvGetParams() to extract and print a list of movie and track parameters.

Setting and Getting Global Movie Properties

Global movie properties apply to the movie as a whole.

You can set these global movie properties:

  • comment

  • loop limit

  • loop mode

  • title

The read-only (computed by the Movie Library) global movie properties are:

  • file format, which is established when the movie is created

  • optimization

You can set and get global movie properties individually, using the Movie Library mvSetParams() and mvGetParams() routines or the DM Library dmSetParams() and dmGetParams() routines.

You can make a default parameter-value list to use when creating a movie by calling mvSetMovieDefaults(), as described in “Creating a Default Movie Configuration”. If you set the default movie parameters by calling mvSetMovieDefaults(), then other parameters, such as the title, require setting only if they differ from the defaults.

This section explains how to set and get the global movie properties individually using Movie Library convenience routines that are built on top of the mvSetParams() and mvGetParams() calls.

Setting and Getting the Movie Comment

To store a comment string in a movie file, call mvSetComment(). Its function prototype is:

DMstatus mvSetComment( MVid movie, const char* comment )

To retrieve the comment string that is stored in a movie file, call mvGetComment(). Its function prototype is:

const char* mvGetComment( MVid movie )

Setting and Getting the Default Movie Loop Mode

The Silicon Graphics movie file format lets you store a default loop mode setting within a movie file. When opening a movie file, the Movie Library obtains the default loop mode from the movie if it is set; otherwise, it assumes MV_LOOP_NONE is the default loop mode.

To store a default loop mode setting in a movie file, call mvSetLoopMode(). Its function prototype is:

DMstatus mvSetLoopMode( MVid movie, MVloopmode mode )

where:

mode 

determines the default loop mode:

MV_LOOP_NONE

sets the default mode to play the movie once

MV_LOOP_CONTINUOUSLY

sets the default mode to play the movie repeatedly

MV_LOOP_SWINGING

sets the default mode to play the movie forward, then backward repeatedly


You can set the playback loop mode independently of the default loop mode by using mvSetPlayLoopMode(), as described in “Looping” in Chapter 30.

To retrieve the loop mode setting that is stored in a movie file, call mvGetLoopMode(). Its function prototype is:

MVloopmode mvGetLoopMode( MVid movie )

Setting and Getting the Default Movie Loop Limit

You can store a default loop limit setting in the movie file that defines the default for the number of movie loops a movie will play if its loop mode is set to MV_LOOP_CONTINUOUSLY or MV_LOOP_SWINGING. To store a default loop limit in a movie file, call mvSetLoopLimit(). Its function prototype is:

DMstatus mvSetLoopLimit( MVid movie, int limit )

where:

limit 

is the number of movie loops allowed; a value of 0 means that the movie will loop indefinitely

To retrieve the default loop limit setting that is stored in a movie file, call mvGetLoopLimit(). Its function prototype is:

int mvGetLoopLimit( MVid movie )

Setting and Getting the Movie Title

To store a title string in a movie file, call mvSetTitle(). Its function prototype is:

DMstatus mvSetTitle( MVid movie, const char* title )

To retrieve the title string that is stored in a movie file, call mvGetTitle(). Its function prototype is:

const char* mvGetTitle( MVid movie )

Getting the Movie File Format

To retrieve the file format of a movie file, call mvGetFileFormat(). Its function prototype is:

MVfileformat mvGetFileFormat( MVid movie )

mvGetFileFormat() returns the file format of the movie:

MV_FORMAT_SGI_1

Silicon Graphics version 1 format

MV_FORMAT_SGI_2

Silicon Graphics version 2 format

MV_FORMAT_SGI_3

Silicon Graphics version 3 format

MV_FORMAT_QT

Apple QuickTime format


Getting the Movie Optimization Setting

To determine whether a movie is optimized for playback, call mvGetOptimized(). Its function prototype is:

DMboolean mvGetOptimized( MVid movie )

mvGetOptimized() returns DM_TRUE if the movie is optimized for playback performance and DM_FALSE if it is not. Performing any editing operations on the movie that read, write, insert, or delete frames will disrupt the optimization and clear this flag. See “Optimizing a Movie File” in Chapter 29 for more information about movie optimization.

Creating a Default Movie Configuration

To make a default parameter-value list that can be used to create a movie, call mvSetMovieDefaults(), which takes the desired format for the new movie file and sets the rest of the movie parameters (such as loop mode) to their default values. Its function prototype is:

DMstatus mvSetMovieDefaults ( DMparams* params,
                              MVfileformat format)

format 

sets the file format of the movie:

MV_FORMAT_SGI_3

Silicon Graphics version 3 format

MV_FORMAT_QT

Apple QuickTime format


Table 28-1 lists the parameters and values set by mvSetMovieDefaults().

Table 28-1. Movie Defaults

Parameter

Value Type

Default

MV_COMMENT

String

Empty

MV_FILE_FORMAT

MVfileformat

format

MV_LOOP_LIMIT

Integer

0

MV_LOOP_MODE

MVloopmode

MV_LOOP_NONE

MV_OPTIMIZED

DMboolean

DM_FALSE

Example 28-1 is a code fragment that creates a parameter-value list called params, then initializes params to the movie defaults by calling mvSetMovieDefaults(), and then passes params to mvCreateFile() to configure a new movie file. After the movie has been created, the parameter-value list is destroyed by calling dmParamsDestroy().

Example 28-1. Creating and Initializing a Default Movie Parameter-value List

MVid movie;
DMparams* params;

if ( dmParamsCreate( &params ) != DM_SUCCESS ) {
    printf( "Out of memory.\n" );
    exit( 1 );
    }
if ( mvSetMovieDefaults(params, MV_FORMAT_SGI_3) != DM_SUCCESS ) {
    printf( "Out of memory.\n" );
    exit( 1 );
    }
if ( mvCreateFile("temp.mv", params, NULL, &movie) != DM_SUCCESS ) {
    printf( "Could not create movie.\n" );
    exit( 1 );

    }
dmParamsDestroy( params );


Adding Your Own Parameters to the Movie Library

You can add your own movie parameters to the Movie Library to represent movie and track properties that do not exist in the parameters provided by the Movie Library. These parameters are global, meaning that any movie opened from within your application will recognize and have access to the parameters defined by the application. User-defined parameters exist as long as the application is running.

To add your own parameters to the Movie Library, call mvAddUserParam(). Its function prototype is:

DMstatus mvAddUserParam ( const char* paramName )

where:

paramName 

is a string containing 15 or fewer characters that uniquely describes the parameter; for example, use a company abbreviation as a prefix for the parameter name


Note: Only null-terminated strings of less than 32 K bytes can be used for user-defined parameter-value pairs.

Once the parameters have been added, you can set and get them just like the regular Movie Library parameters. To set the values for the parameters, pass a list of the parameters and values to mvSetParams().

You must add the parameters before calling any of the routines for setting and getting their values. If you call mvSetParams() before calling mvAddUserParam(), the Movie Library will not recognize the parameters and they will be ignored.

If you open a movie that contains user-defined parameters, you can read those parameters because the Movie Library automatically calls mvAddUserParam() when loading a movie with user-defined parameters.

Example 28-2 is a code fragment that adds a user-defined global movie parameter named Newparam to a Movie Library application, then creates a movie that has access to the user-defined parameter.

Example 28-2. Adding a User-Defined Global Movie Parameter

/*
 * Adding a global (movie) user param named Newparam with a value of
 * "Movie type code 1113afq1" to a new movie file.
 */

    DMparams* movieParams;
  
    if ( dmParamsCreate( &movieParams ) != DM_SUCCESS ) {
        fprintf( stderr, "Unable to create default params.\n");
        exit( EXIT_FAILURE );
    }
    if ( mvSetMovieDefaults( movieParams, MV_FORMAT_SGI_3 )
        != DM_SUCCESS ) {
        fprintf( stderr, "Unable to set default params.\n");
        dmParamsDestroy( movieParams );
        exit( EXIT_FAILURE );
    }
    if ( mvAddUserParam( "Newparam" ) != DM_SUCCESS ) {
        fprintf( stderr, "Unable to add user param.\n");
        dmParamsDestroy( movieParams );
        exit( EXIT_FAILURE );
    }
    if ( dmParamsSetString( movieParams, "Newparam",
                           "Movie type code 1113afq1" )
                           != DM_SUCCESS ) {
         fprintf( stderr, "Unable to set user param.\n");
         dmParamsDestroy( movieParams );
         exit( EXIT_FAILURE );
    }
    if ( mvCreateFile( "mymovie", movieParams,
                      NULL, theMovie ) == DM_FAILURE ) {
        fprintf( stderr,
                "Unable to create movie file %s: error =  %s.\n",
                getOutMovieName(),mvGetErrorStr( mvGetErrno() ) );
        dmParamsDestroy( movieParams );
        exit( EXIT_FAILURE );
    }

Example 28-3 is a code fragment that adds a user-defined image track parameter named NewImageParam to a Movie Library application, and then adds an image track that has access to the user-defined parameter.

Example 28-3. Adding a User-Defined Image Track Parameter for a New Track

/*
 * Adding a usr param named NewImageParam with a value of
 * "Source code a32bg" to an image track.
 */
    DMparams *imageTrackParams;

    if ( dmParamsCreate( &imageTrackParams ) != DM_SUCCESS ) {
        fprintf( stderr, "Unable to create image track params.\n");
        exit( EXIT_FAILURE );
    }
    if ( dmSetImageDefaults( imageTrackParams, imgWidth, imgHeight,
                            DM_PACKING_RGBX ) != DM_SUCCESS ) {
        fprintf( stderr, "Unable to set image defaults.\n");
        dmParamsDestroy( imageTrackParams );
        exit( EXIT_FAILURE );
    }
    if ( mvAddUserParam( "NewImageParam" ) != DM_SUCCESS ) {
        fprintf( stderr, "Unable to add user param.\n");
        dmParamsDestroy( imageTrackParams );
        exit( EXIT_FAILURE );
    }
    if ( dmParamsSetString( imageTrackParams, "NewImageParam",
                           "Source code a32bg" ) != DM_SUCCESS ) {
        fprintf( stderr, "Unable to set user param.\n");
        dmParamsDestroy( imageTrackParams );
        exit( EXIT_FAILURE );
    }

    /*
     * Add the image track to the movie.
     */
    MVid imageTrack;
    if ( mvAddTrack( movie, DM_IMAGE, imageTrackParams,
                    NULL, &imageTrack ) == DM_FAILURE) {
        fprintf( stderr, "Unable to add image track to movie.\n");
        dmParamsDestroy( imageTrackParams );
        exit( EXIT_FAILURE );
    }
    dmParamsDestroy( imageTrackParams );


Setting and Getting Track Properties

The Movie Library lets you work with the individual image and audio tracks inside movies. A track is an evenly spaced (in time) sequence of frames, where each of the frames is the same size (although the amount of data per frame may vary after compression).

This section explains how to use the Movie Library routines for setting and getting both general track properties, which apply to all tracks, and specific track properties, which depend upon the track medium.

You can set this general track property for all types of tracks:

  • SMPTE time code string

The read-only general track properties are:

  • track length (number of frames)

  • track medium (image or audio)

Setting and Getting General Track Properties

This section explains how to set and get the general track properties using the Movie Library convenience routines, which are built on top of the universal set and get routines mvSetParams() and mvGetParams(). You can also set and get general track properties by calling mvSetParams() and mvGetParams(), respectively.

Setting and Getting SMPTE Time Code Strings Stored in Tracks

You can store SMPTE time codes as strings in a track parameter. The time code string does not have any relationship to a timer inside the Movie Library, so you have to obtain the time code from an external source before storing it as a parameter. See “Using the SMPTE Time Code Sample Application” in Chapter 32 for sample programs that implement time code capability.

To store a SMPTE time code string in a movie track, call mvSetSMPTEStart(). Its function prototype is:

DMstatus mvSetSMPTEStart(MVid movie, const char* start_time)

where:

start_time 

is a string representing a SMPTE time code, with two digits each for hour, minute, second, and frame, as in "00:59:30:00"

mvSetSMPTEStart() returns either DM_SUCCESS or DM_FAILURE.

To retrieve a SMPTE time code string that is stored in a movie track, call mvGetSMPTEStart(), which returns the starting time code as set by mvSetSMPTEStart(). Its function prototype is:

const char* mvGetSMPTEStart( MVid track )

where:

track 

is the track for which you want to obtain the SMPTE time code parameter

Getting the Track Length

To retrieve the number of frames stored in a track, call mvGetTrackLength(). Its function prototype is:

MVframe mvGetTrackLength ( MVid track )

Getting the Track Medium

To determine the track medium, call mvGetTrackMedium(). Its function prototype is:

DMmedium mvGetTrackMedium( MVid track )

mvGetTrackMedium() returns either DM_IMAGE or DM_AUDIO.

Setting and Getting Audio Track Properties

The audio track of a movie contains digitized audio samples.

When creating an audio track, you can set and get audio properties individually, using the Movie Library mvSetParams() and mvGetParams() routines or the DM Library dmSetParams() and dmGetParams() routines.

You can also create default audio parameters for an audio track using the DM Library dmSetAudioDefaults() routine. If you set the audio defaults by calling dmSetAudioDefaults(), then other properties, such as number of channels, require setting only if they differ from the defaults.

You can set these properties when creating an audio track:

  • audio sample format

  • audio sample rate

  • audio sample width (bytes per sample)

  • number of audio channels

The only parameter that you can change for an existing audio track is the default volume (this is not functional in the current version of the Movie Library). The other parameters cannot be changed after a track has been created because they would invalidate the data stored in the track.

Table 28-2 lists the audio defaults as set by dmSetAudioDefaults().

Table 28-2. Audio Defaults

Parameter

Value Type

Default

DM_MEDIUM

DMmedium

DM_AUDIO

DM_AUDIO_WIDTH

Integer

width

DM_AUDIO_FORMAT

DMaudioformat

DM_AUDIO_TWOS_COMPLEMEN T

DM_AUDIO_RATE

Double

rate

DM_AUDIO_CHANNELS

Integer

channels

DM_AUDIO_COMPRESSIO N

String

DM_AUDIO_UNCOMPRESSED



Note: Currently, only DM_AUDIO_UNCOMPRESSED is supported for audio compression.

Since the Movie Library guarantees that all audio tracks have all of these parameters defined, the “get” routines in this section do not return errors.

Setting and Getting the Default Volume of an Audio Track

mvSetDefaultVol() stores a new value, ranging from 0.0 to 1.0, for the default volume parameter. It returns DM_SUCCESS or DM_FAILURE. Its function prototype is:

int mvSetDefaultVol( MVid audioTrack double volume)

mvGetDefaultVol() returns the default volume setting to use when playing this movie. Its function prototype is:

DMstatus mvGetDefaultVol( MVid audioTrack )

where:

audioTrack 

is the audio track whose volume you want to set or get


Note: The Movie Library currently ignores the default volume setting.


Getting the Audio Sample Width of an Audio Track

The Movie Library supports 8-bit and 16-bit audio samples.

To determine the number of bits used to store each audio sample in an audio track, call mvGetAudioWidth(). Its function prototype is:

int mvGetAudioWidth( MVid audioTrack )

where:

audioTrack 

is the audio track whose sample width you want to know

Getting the Audio Sample Rate of an Audio Track

To determine the audio sample rate (in samples per second) for an audio track, call mvGetAudioRate(). Its function prototype is:

double mvGetAudioRate( MVid audioTrack )

where:

audioTrack 

is the audio track whose sample rate you want to know

Getting the Number of Audio Channels in an Audio Track

To determine the number of audio channels in an audio track, call mvGetAudioChannels(). Its function prototype is:

int mvGetAudioChannels( MVid audioTrack )

mvGetAudioChannels() returns the number of audio channels: 1 for mono; 2 for stereo (the Movie Library does not currently support 4-channel audio tracks).

where:

audioTrack 

is the audio track for which you want to know the number of channels

Getting the Audio Format of an Audio Track

The Movie Library supports both unsigned and twos complement audio formats that are directly understood by the Audio Library (AL), in particular the ALwritesamps() call, for Silicon Graphics native movie formats.

Audio for QuickTime movies is stored using sampling rates and formats understood by QuickTime on the Apple Macintosh computer. Some of these formats are not directly supported by the AL. See Chapter 31, “Using the Movie Library with QuickTime Movies,” for more information on QuickTime audio.

To determine the format used to store the audio samples in an audio track, call mvGetAudioFormat(). Its function prototype is:

DMaudioformat mvGetAudioFormat( MVid audioTrack )

where:

audioTrack 

is the audio track whose format you want to know

mvGetAudioFormat() returns either DM_AUDIO_TWOS_COMPLEMENT or DM_AUDIO_UNSIGNED.

Getting the Audio Compression Scheme of an Audio Track

To determine the audio compression scheme for an audio track, call mvGetAudioCompression(). Its function prototype is:

const char* mvGetAudioCompression( MVid audioTrack )

where:

audioTrack 

is the audio track whose compression you want to know

Since movies do not currently support audio compression, the only valid value is DM_AUDIO_UNCOMPRESSED.

Setting and Getting Image Track Properties

The image track of a movie contains a sequence of image frames. All the images in an image track must have the same frame size (width and height).

When creating an image track, you can set and get image properties individually, using the Movie Library mvSetParams() and mvGetParams() routines or the DM Library dmSetParams() and dmGetParams() routines.

You can also create default image parameters for an image track using the DM Library dmSetImageDefaults() routine. If you set the image defaults by calling dmSetImageDefaults(), then other properties, such as compression, require setting only if they differ from the defaults.

Table 28-3 lists the image defaults as set by dmSetImageDefaults().

Table 28-3. Image Defaults

Parameter

Value Type

Value

DM_MEDIUM

DMmedium

DM_IMAGE

DM_IMAGE_WIDTH

Integer

width

DM_IMAGE_HEIGHT

Integer

height

DM_IMAGE_RATE

Double

15.0

DM_IMAGE_COMPRESSION

String

DM_IMAGE_UNCOMPRESSED

DM_IMAGE_INTERLACING

DMinterlacing

DM_IMAGE_NONINTERLACED

DM_IMAGE_PACKING

DMpacking

packing

DM_IMAGE_ORIENTATION

DMorientatio n

DM_BOTTOM_TO_TOP

The only parameter that you can change for an existing image track is the image frame rate. The other parameters cannot be changed after a track has been created because they would invalidate the data stored in the track.

Since the Movie Library guarantees that all image tracks have all image parameters defined, the “get” routines in this section do not return errors.

Setting and Getting the Image Frame Rate

To change a movie's frame rate by storing a new value for the image rate parameter, call mvSetImageRate(). Its function prototype is:

DMstatus mvSetImageRate( MVid imageTrack,
                         double framesPerSecond )

where:

imageTrack

is the image track for which you want to set the rate

 

framesPerSecond

is the image rate in frames per second

mvSetImageRate() returns DM_SUCCESS if the image rate was successfully changed; otherwise, it returns DM_FAILURE.

To determine the image rate in frames per second for a movie, call mvGetImageRate(). Its function prototype is:

double mvGetImageRate( MVid imageTrack )

where:

imageTrack 

is the image track whose rate you want to know

Getting the Image Frame Size

To get the width (x dimension) in pixels of the images stored in an image track, call mvGetImageWidth(). Its function prototype is:

int mvGetImageWidth( MVid imageTrack )

where:

imageTrack 

is the image track whose dimensions you want to know

To get the height (y dimension) in pixels of the images stored in an image track, call mvGetImageHeight(). Its function prototype is:

int mvGetImageHeight( MVid imageTrack )

where:

imageTrack 

is the image track whose dimensions you want to know

Getting the Image Orientation

The ordering of scan lines within an image frame depends upon the source of the data. Bottom-to-top is the default data orientation for Movie Library routines. To find out how pixels are ordered, call mvGetImageOrientation(). Its function prototype is:

DMorientation mvGetImageOrientation ( MVid imageTrack)

where:

imageTrack 

is the image track whose format you want to know

mvGetImageOrientation() returns the order in which scan lines are stored in the image: DM_BOTTOM_TO_TOP or DM_TOP_TO_BOTTOM.

Getting the Image Format

The Movie Library can read images from and write images to a buffer. You can use the IRIS ImageVision Library to read any of these image formats into a buffer:

FIT 

Silicon Graphics ImageVision Library tiled image format

GIF 

Compuserve Graphics Image File, a popular 8-bit format

PCD 

Kodak Photo CD file format for digital images

SGI 

Silicon Graphics image data formats: .bw, .rgb, .rgba, .sgi, and .screen

TIFF 

extended version of Tag Image File Format, Revision 6.0

Getting the Image Packing Format

The image packing format describes how pixels are packed within images; for example, the word length used to represent the pixel, and the bit order.

Images in a movie file can be stored on disk in any of the image packing formats listed in Table 28-4. When you play a movie whose image track is in a nondefault format, the Movie Library converts the image data to DM_PACKING_RGBX on the fly as it plays the movie.

To get the image packing format for a particular image track, call mvGetImagePacking(). Its function prototype is:

DMpacking mvGetImagePacking( MVid imageTrack )

where:

imageTrack 

is the ID of the image track whose format you want to know

Table 28-4 lists the image packing formats supported by the Movie Library

Table 28-4. Image Packing Formats

Packing Format

Description

DM_PACKING_RGBX

R, G, B, and X (don't care) data are packed into a 32- bit word as 0xXXBBGGRR. This is the default format for the Movie Library.

DM_PACKING_GRAYSCAL E

Each pixel is an 8-bit luminance value.

DM_PACKING_APPLE_16

16-bit images are stored with 5 bits each of red, green, and blue. The bit layout is:

XRRRRRGGGGGBBBBB

Apple stores images from top to bottom, while SGI goes from bottom to top.

DM_PACKING_APPLE_32

32-bit images are stored with 8 bits each of red, green, and blue. The bit layout is:

XXXXXXXXRRRRRRRRGGGGGGGGBBBBBBBB


Getting the Image Compression Scheme

Compression settings can result in significant differences in image quality and in playback performance. The most commonly used compression schemes for movies to be played on Silicon Graphics computers are MVC1 and MVC2; QT_VIDEO is frequently used for QuickTime movies to be played on a Macintosh computer.

The Movie Library supports image compression through the Compression Library. The compression methods that have been thoroughly tested with the Movie Library are UNCOMPRESSED, MVC1, MVC2, RLE24, and JPEG. You can also use the QuickTime compression schemes, QT_VIDEO and QT_ANIM, in QuickTime and Silicon Graphics movies if you have purchased and installed the Silicon Graphics QuickTime Compressor Library.

To get the image compression scheme, call mvGetImageCompression(). Its function prototype is:

const char* mvGetImageCompression( MVid imageTrack )

where:

imageTrack 

is the ID of the image track whose format you want to know

mvGetImageCompression() returns the name of the compression scheme that is used to compress the images.

The most commonly used schemes and the reasons for choosing them are:

UNCOMPRESSED

For the best quality in a final movie, all image manipulation and storage should be with uncompressed images until the final movie is produced, at which time the images can be compressed. Repeatedly compressing, decompressing, and then recompressing images reduces the image quality.

MVC1

This is a good general-purpose compression scheme. It is a color-cell compression technique that works well for video, but can cause fuzzy edges in high-contrast animation.

MVC2

Provides results similar to MVC1 in terms of image quality. MVC2 compresses the data more than MVC1, but takes longer to perform the compression. Playback is faster for MVC2, because there is less data to read in, and decompression is faster than for MVC1.

RLE24

This is a lossless compression method that uses run-length encoding (RLE). Run-length encoding compresses images by storing a color and its run-length (the number of pixels of that color) every time the color changes. It is a good technique for animations where there are large areas that have identical colors.

JPEG

JPEG is designed for still images and is usable, but slow, for video. JPEG is typically used to compress each still frame during the writing or editing process, with the intention being to apply another type of compression to the final version of the movie or to leave it uncompressed. JPEG works better on high-resolution, continuous-tone images such as photographs, than on crisp-edged, high-contrast images like line drawings.

QT_VIDEO

This is the compression used for QuickTime movies that contain video. Like MVC1, QT_VIDEO is a color-cell compression technique. It includes temporal compression and is good for video and reasonable for animation.

QT_ANIM

This is a lossy run-length encoding scheme used for QuickTime movies. It also includes temporal compression. It has excellent compression ratios for animation that has large areas of similar colors.