从 AVAssetReaderOutput 读取数据时 iOS 5.0 崩溃
我有这段代码用于从 AVAssetReaderOutput
读取数据,该方法在 iOS 4.0 中运行良好,但是在 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];
}
谢谢
丹尼尔
I have this snippet of code used to read data from an AVAssetReaderOutput
, the method works fine in iOS 4.0, however in 5.0 it crashes towards the end with bad access, not sure why, anyone have any input?
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];
}
Thanks
Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,我通过检查 blockBuffer 是否为空并继续(如果为空)来修复此问题,问题是 ref 不为空,但 blockBuffer 为空,因此这段代码解决了我的问题
I actually fixed this by checking that blockBuffer was null and continuing if it was, the problem was that ref was not null but the blockBuffer was so this code fixed my issue