我从视频资源的使用aVFoundation框架阅读CMSampleBufferRef,在一个while循环,我收到那些图像象下面这样:当while循环执行它iPhone - 收到内存警告
-(void)splitImagesFromVideo
{
if (images != nil) {
[images release];
images = nil;
}
images =[[NSMutableArray alloc] init];
NSURL *fileURL = [[NSBundle mainBundle]
URLForResource:@"3idiots" withExtension:@"mov"];
NSLog(@"video: %@",videoURL);
AVAsset *theAVAsset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
NSError *error = nil;
float width = theAVAsset.naturalSize.width;
float height = theAVAsset.naturalSize.height;
AVAssetReader *mAssetReader = [[AVAssetReader alloc] initWithAsset:theAVAsset error:&error];
NSArray *videoTracks = [theAVAsset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *videoTrack = [videoTracks objectAtIndex:0];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
AVAssetReaderTrackOutput* mAssetReaderOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack outputSettings:options];
[mAssetReader addOutput:mAssetReaderOutput];
BOOL success = [mAssetReader startReading];
NSInteger val = 1;
while ([mAssetReader status]==AVAssetReaderStatusReading){
CMSampleBufferRef buffer = [mAssetReaderOutput copyNextSampleBuffer];//read next image.
if (buffer) {
UIImage *img = [self imageFromSampleBuffer:buffer];
if (img != nil) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
img = [self imageOfSize:CGSizeMake(320, 480) fromImage:img];
[images addObject:img];
[pool release];
}
CMSampleBufferInvalidate(buffer);
CFRelease(buffer);
buffer = nil;
}
NSLog(@"value: %d", val++);
}
[images removeLastObject];
NSLog(@"img count: %d", [images count]);
NSLog(@"imgs: %@",images);
[theAVAsset release];
[mAssetReader release];
[mAssetReaderOutput release];
NSLog(@"count: %d", [images count]);
}
打印我把日志递增整数val
。 ,并且在这段时间之间在GDB中显示消息“接收到的内存警告”。
非常感谢......
你怎么到内存警告作出反应?你的问题到底是什么?你在调查潜在的内存泄漏吗?如果是这样,你是否尝试过分析仪工具? – 2012-07-25 07:09:50
您没有显示足够的代码。例如,什么是'[self imageFromSampleBuffer:]'?我们不知道,那么我们怎么知道你在记忆中可能用这种方法做什么?没有理由认为问题出现在你刚才在这里展示的片段中。 – matt 2012-09-07 21:11:58