【发布时间】:2012-07-25 06:27:31
【问题描述】:
我正在使用 aVFoundation 框架从视频资产中读取 CMSampleBufferRef,在一段时间循环中,我得到如下图像:
-(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]);
}
当 while 循环执行时,它会打印我输入的日志,并增加整数 val。
在这之间,有时 GDB 中会显示一条消息“Received Memory Warning”。
非常感谢...
【问题讨论】:
-
你对那个内存警告有什么反应?你的问题到底是什么?您是否正在调查潜在的内存泄漏?如果是这样,您是否尝试过分析工具?
-
您没有显示足够的代码。例如,
[self imageFromSampleBuffer:]是什么?我们不知道,那么我们怎么知道您可能在该方法中使用内存做什么呢?没有理由认为问题出在您恰好在此处显示的 sn-p 中。
标签: iphone objective-c memory-management avfoundation