Documentation Archive Developer
Search

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

paramErr returned from ConvertMovieToFile when exporting to .wav


Q: I'm trying to use the SndSnip_ConvertWAVEFormats code to convert 16-bit 44.1kHz movie sound tracks to 8-bit 22kHz .wav files, but ConvertMovieToFile always returns a paramErr (-50) even though MovieExportSetSampleDescription never returns an error. I modified the Sound Description to fit my needs (listed below), any ideas what could be wrong?

(**myDesc).descSize = sizeof(SoundDescription);
(**myDesc).sampleSize = 8;
(**myDesc).sampleRate = rate22050hz;
(**myDesc).dataFormat = k8BitOffsetBinaryFormat;

A: SndSnip_ConvertWAVEFormats did not previously set the value for numChannels in the Sound Description. This resulted in an incorrect default value of 0 being used. A paramErr is always returned from the Sound Export Component if either numChannels, sampleRate or sampleSize has a value of 0 and would have affected the code even when not specifically exporting to a .wav file.

Listing 1 demonstrates the function using your specified sound description.

Listing 1. MyConvertToWAV

OSErr MyConvertToWAV(Movie theMovie, FSSpec *theFile)
{
  ComponentInstance      myComponent = NULL;
  SoundDescriptionHandle myDesc = NULL;
  ComponentResult        myErr = badComponentType;

  // open the export component - sound exporter to .wav file
  myComponent = OpenDefaultComponent(MovieExportType, kQTFileTypeWave);

  // return a -2005 error if we can't find the component
  if (myComponent == NULL) goto bail; 

  // create and fill in a sound description
  myDesc = (SoundDescriptionHandle)NewHandleClear(sizeof(SoundDescription));
  if (myDesc == NULL) {
    myErr = MemError();
    goto bail;
  }

  // this is the format we want, the dataFormat for a .wav can either be
  // k8BitOffsetBinaryFormat or k16BitLittleEndianFormat 
  (**myDesc).descSize = sizeof(SoundDescription);
  (**myDesc).numChannels = 2;
  (**myDesc).sampleSize = 8;
  (**myDesc).sampleRate = rate22050hz; 
  (**myDesc).dataFormat = k8BitOffsetBinaryFormat;

  // tell the export component to use the sound characteristics
  // specified in the sound description
  myErr = MovieExportSetSampleDescription(myComponent,
                                         (SampleDescriptionHandle)myDesc,
                                          SoundMediaType);
  if (myErr != noErr) goto bail;
 
  // export the movie into a file
  myErr = ConvertMovieToFile(theMovie, // the movie to convert
                             NULL,     // all tracks
                             theFile,  // the output file
                             kQTFileTypeWave,        // file type (.wav)
                             FOUR_CHAR_CODE('TVOD'), // file creator
                             smSystemScript,         // the script
                             NULL, // no resource ID to be returned
                             0L,   // no flags (ie. no Settings Dialog)
                             myComponent); // the export component

bail:
  // dispose of any storage we allocated
  if (myComponent != NULL)
    CloseComponent(myComponent);
       
  if (myDesc != NULL)
    DisposeHandle((Handle)myDesc);

  return myErr;
}



[Oct 06, 2003]