1

I had captured the video using AVFoundation and When I am trying to convert the video captured into Frames my app is crashed coz of low memory. I am using the project with ios 5.1 and ARC enabled.

Here my code follows:

-(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;

}

Anyone pls advice me what to do.

Regards, Monish.

4

1 回答 1

1

您可能需要使用 CFRelease(cgImageRef) 来释放 CGImageRef 对象。您可以转到 Xcode 并在产品栏中单击分析。它将帮助您分析您的代码,并可能给您带来可能的内存泄漏。

于 2012-06-12T15:37:46.787 回答