I’m getting an invalid track code (-2009) when exporting WAVE audio to MP4. Can anyone offer a solution?
// Initialize the QuickTime environment.
InitializeQTML(0L); // Initialize QTML
EnterMovies(); // Initialize QuickTime
// Format the input WAVE file name.
FSSpec inFileRec, outFileRec;
NativePathNameToFSSpec(
“G:\\Music\\WAV Unnormalized\\Sex Bomb (Peppermint Disco Mix) – Tom Jones & Mousse T..wav”,
&inFileRec,
0L);
// Format the output file name.
NativePathNameToFSSpec(
“G:\\Music\\Mp4\\Sex Bomb (Peppermint Disco Mix) – Tom Jones & Mousse T..mp4″,
&outFileRec,
0L);
// Open the input WAVE file for reading.
short inFileRefNum;
OSErr nErr = OpenMovieFile(&inFileRec, &inFileRefNum, fsRdPerm);
// Create a QuickTime movie (in memory) from the WAV file.
Movie movie = NULL;
short inResId = 0;
Str255 strName;
Boolean bWasChanged;
nErr = NewMovieFromFile( &movie,
inFileRefNum,
&inResId,
NULL,
newMovieActive,
&bWasChanged);
long trackCount = GetMovieTrackCount(movie);
// This call ^^^ returns a track count of 1, which is seems reasonable. My WAV files are stereo
// however, so should this count perhaps be 2 ?
// At any rate, things appear to be working correctly so far…
// Get the MP4 component for the exportation, so I can set certain export parameters…
Component c = 0;
ComponentInstance theExporter = NULL;
ComponentDescription cd =
{
kAnyComponentType,
kQTFileTypeMP4,
kAppleManufacturer,
0,
0};
OSErr err = invalidComponentID;
c = FindNextComponent(0, &cd);
if (c == 0)
{
MessageBox(hWnd, “Could not find component.”, “Error”, MB_OK);
}
err = OpenAComponent(c, &theExporter);
if (err || theExporter == 0)
{
MessageBox(hWnd, “Could not open the MP4 exporter.”, “Error”, MB_OK);
};
// find the first sound track in the specified movie
Track myTrack = GetMovieIndTrackType(movie, 1, AudioMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly);
if (myTrack == NULL)
{
MessageBox(hWnd, “Could not get audio track.”, “Error”, MB_OK);
}
// I called the GetMovieIndTrackType() function just to verify that the track information could be
// retrieved.
// So far, so good. All functions to this point succeed.
// Now, export the audio-only movie to MP4…
err = ConvertMovieToFile(movie,
NULL,
&outFileRec,
kQTFileTypeMP4,
FOUR_CHAR_CODE(‘TVOD’),
smSystemScript,
NULL,
showUserSettingsDialog | movieToFileOnlyExport |movieFileSpecValid, theExporter);
// This ConvertMovieToFile() call ^^^^ is returning the -2009 error and I just don’t understand why.
// Close the movie.
CloseComponent(theExporter);
CloseMovieFile(inFileRefNum);
DisposeMovie(movie);
// Properly clean up and stop the QuickTime functionality.
ExitMovies(); // Terminate QuickTime
TerminateQTML(); // Terminate QTML