2

I currently use the following code to shoot a series of images:

- (void)shootSeries:(int)photos {
    if(photos == 0) {
        [self mergeImages];
    } else {
        [output captureStillImageAsynchronouslyFromConnection:connection completionHandler:
            ^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
                NSLog(@"Shot picture %d.", 7 - photos);
                [self shootSeries:(photos - 1)];

                CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(imageDataSampleBuffer);

                CVPixelBufferLockBaseAddress(pixelBuffer, 0);
                int dataSize = CVPixelBufferGetDataSize(pixelBuffer);
                CFDataRef data = CFDataCreate(NULL, (const UInt8 *)CVPixelBufferGetBaseAddress(pixelBuffer), dataSize);
                CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

                CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data);
                CFRelease(data);

                CGImageRef image = CGImageCreate(CVPixelBufferGetWidth(pixelBuffer),
                                                 CVPixelBufferGetHeight(pixelBuffer),
                                                 8, 32,
                                                 CVPixelBufferGetBytesPerRow(pixelBuffer),
                                                 colorspace,
                                                 kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little,
                                                 dataProvider, NULL, true, kCGRenderingIntentDefault);
                CFRelease(dataProvider);

                CFArrayAppendValue(shotPictures, image);
                CFRelease(image);
            }];
    }
}

While this works rather well it is very slow. How come apps like ClearCam can shoot pictures much faster in series than this and how can I do it too?

Emil Eriksson
  • 2,110
  • 1
  • 21
  • 31
  • Did you figure this out? If so, I'd appreciate if you could post the answer. I've tried a bunch of techniques such as creating multiple inputs and outputs and cycling between them, or adding/removing inputs/outputs after each take. My issue is that if the user is allowed to take photos really quickly you end up with NULL CMSampleBuffers and "AVFoundation out of memory" errors. The end result is that some of the photos get lost, which is obviously worse than forcing them to take photos more slowly. – Jon G. May 31 '11 at 22:20

1 Answers1

0

After capturing the image, store the sample buffer in a CFArray, and once you're done taking all your phones, THEN convert them to images (or in your case CGImageRefs).

Riley Testut
  • 431
  • 1
  • 8
  • 22
  • I have now tried many hours to save to CFMutableArray and after convert to UIImages, but I just can't get it to work. Do you have any example code for this? – Snilleblixten Oct 07 '11 at 16:28