我最近继承了一个使用quicktime的代码库,我注意到当使用下面的函数导入移动时,它大部分时间都可以工作,但随后会偶尔崩溃。当它崩溃时很奇怪,因为它连续工作10次然后它会使应用程序崩溃。
我在C中使用winapi作为我的应用程序。 IDE:Visual Studio 8 操作系统:Windows 7 Quicktime版本:最新
这来自Quicktime API文档:
PutMovieIntoTypedHandle
从该影片中拍摄一部电影或一首曲目,并将其转换为指定类型的句柄。
OSErr PutMovieIntoTypedHandle( 电影theMovie, 跟踪targetTrack, OSType handleType, 处理publicMovie, TimeValue开始, TimeValue dur, 长旗, ComponentInstance userComp );
守则:
Track newTrack;
FSSpec audioFile;
Movie audioFileMovie;
Track audioFileTrack;
Media audioFileMedia;
TimeValue audioTrackDuration;
long trackCount;
short audioRefNum;
TimeScale audioTimeScale;
OSErr err;
SoundDescriptionHandle outDesc, inDesc;
ComponentInstance soundComp =0;
SndListResource * slr;
SoundHeader * sh;
Handle soundData = NewHandle(0);
long i,sampleOffset,actualSamples, sampleCount;
//Create dataRef from audioFilePath
if((err = NativePathNameToFSSpec(audioFilePath, &audioFile, kErrorIfFileNotFound)) != noErr) {
if(err != fnfErr) {
printf("NativePathNameToFSSpec failed. Error: %d\n", err);
return 0;
}
}
if(noErr != OpenMovieFile(&audioFile, &audioRefNum, fsRdPerm)){
fprintf(stderr, "Couldn't open movie file\n");
return 0;
}
NewMovieFromFile(&audioFileMovie, audioRefNum, NULL, (StringPtr)NULL, newMovieActive, NULL);
if (audioRefNum != 0)
CloseMovieFile(audioRefNum);
//see how many tracks there are in the audioFileMovie
trackCount = GetMovieTrackCount(audioFileMovie);
//Obtain audio track from audio movie
audioFileTrack = GetMovieIndTrack(audioFileMovie, 1);
//Obtain audio media from audioFileTrack so that we can figure out how long it is
audioFileMedia = GetTrackMedia(audioFileTrack);
audioTrackDuration = GetMediaDuration(audioFileMedia);
audioTimeScale = GetMediaTimeScale(audioFileMedia);
soundComp = OpenDefaultComponent('spit', 'snd ');
if(!soundComp)
{
return 1;
}
inDesc=(SoundDescriptionHandle)NewHandle(0);
outDesc=nil;
GetMediaSampleDescription(GetTrackMedia(audioFileTrack),1,(SampleDescriptionHandle)inDesc);
outDesc = (SoundDescriptionHandle) NewHandleClear(sizeof(SoundDescription));
if(!outDesc)
{
CloseComponent(soundComp);
return 1;
}
outDesc[0]->descSize = sizeof(SoundDescription);
outDesc[0]->dataFormat = k8BitOffsetBinaryFormat;
outDesc[0]->numChannels = 1;
outDesc[0]->sampleSize = 8;
outDesc[0]->sampleRate = inDesc[0]->sampleRate;
MovieExportSetSampleDescription(soundComp, (SampleDescriptionHandle)outDesc, 'soun');
DisposeHandle((Handle)inDesc);
DisposeHandle((Handle)outDesc);
if( audioFileMovie && soundData && soundComp )
{
MessageBox(NULL, "Entering \"PutMovieIntoTypedHandle\".\n", "Checkpoint" ,MB_OK);
OSErr result = PutMovieIntoTypedHandle(audioFileMovie,0, 'snd ', soundData, 0, // frameTime,
GetMovieDuration(audioFileMovie), 0, soundComp);
MessageBox(NULL, "Made it passed \"PutMovieIntoTypedHandle\".\n", "Checkpoint" ,MB_OK);
}
else
{
return 1;
}