3
我有這段代碼用於從AVAssetReaderOutput
讀取數據,該方法在iOS 4.0中正常工作,但是在5.0中它以不良訪問崩潰,不知道爲什麼,任何人有任何輸入?當從一個AVAssetReaderOutput讀取數據時,iOS 5.0崩潰
AVAssetReaderOutput *output=[myOutputs objectAtIndex:0];
int totalBuff=0;
while(TRUE)
{
CMSampleBufferRef ref=[output copyNextSampleBuffer];
if(ref==NULL)
break;
//copy data to file
//read next one
AudioBufferList audioBufferList;
NSMutableData *data=[[NSMutableData alloc] init];
CMBlockBufferRef blockBuffer;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(ref, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
for(int y=0; y<audioBufferList.mNumberBuffers; y++)
{
AudioBuffer audioBuffer = audioBufferList.mBuffers[y];
Float32 *frame = audioBuffer.mData;
NSLog(@"Gonna write %d", audioBuffer.mDataByteSize);
//crashes here
[data appendBytes:frame length:audioBuffer.mDataByteSize];
}
totalBuff++;
CFRelease(blockBuffer);
CFRelease(ref);
[fileHandle writeData:data];
[data release];
}
感謝
丹尼爾
你是如何解決它的?因爲接受的答案我無法解決。 –
問題是ref沒有返回null,但blockBuffer爲null,所以檢查blockBuffer是否爲null,如果它只是繼續回到循環的頂部,我把答案放在下面並使其成爲acceffered回答 – Daniel
非常感謝。你只是節省了幾個小時的搜索!:D –