AVFoundation を使用してビデオをキャプチャしました。キャプチャしたビデオをフレームに変換しようとすると、メモリ不足のためにアプリがクラッシュします。iOS 5.1 と ARC を有効にしたプロジェクトを使用しています。
ここで私のコードは次のとおりです。
-(void) makeVideoCall
{
videoOutput = [[AVCaptureVideoDataOutput alloc]init];
[captureSession addOutput:videoOutput];
videoOutput.videoSettings =
[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA]
forKey:(id)kCVPixelBufferPixelFormatTypeKey];
videoOutput.alwaysDiscardsLateVideoFrames = YES;
dispatch_queue_t queue = dispatch_queue_create("MyQueue", NULL);
[videoOutput setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);
[videoOutput setSampleBufferDelegate:self queue:queue];
[captureSession startRunning];
}
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
NSLog(@"\n Inside CaptureOutput....");
CGImageRef tempImage = [self imageRefFromSampleBuffer:sampleBuffer];
image = [[UIImage alloc] initWithCGImage:tempImage scale:0.2 orientation:UIImageOrientationLeftMirrored];
}
-(CGImageRef)imageRefFromSampleBuffer:(CMSampleBufferRef)sampleBuffer {
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer,0);
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGImageRef newImage = CGBitmapContextCreateImage(context);
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return newImage;
}
誰でも私に何をすべきかアドバイスしてください。
よろしく、モニッシュ。