【问题标题】:Burst-mode with iPhone and AVFoundation使用 iPhone 和 AVFoundation 的突发模式
【发布时间】:2012-01-03 16:41:01
【问题描述】:

我想使用 AVFoundation 框架实现连拍模式(快速连续 5 次拍摄),但遇到了困难。

for(int imgNum = 0; imgNum < nImages; imgNum++)
{
    float dT = imgNum*4.0 - (CFAbsoluteTimeGetCurrent() - startTime);
    NSLog(@"Waiting for %.02f seconds...\n",dT);
    [NSThread sleepForTimeInterval:dT];
    [self takeStill:videoConnection];
}

- takeStill:(AVCaptureConnection*)videoConnection
{
    [stillOut captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error)
 {
     if(error)
         NSLog(@"%s",[[error localizedDescription] UTF8String]);
     NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
     // {...} Save as a png
 }];
}

以这种方式拍摄一张图像效果很好。看起来,休眠线程会导致完成处理程序永远不会触发,直到所有nImages 都被占用,结果是imageSampleBuffer 为NULL。处理这个问题的正确方法是什么?

【问题讨论】:

    标签: iphone avfoundation


    【解决方案1】:

    试试这个方法:

    - (void)shoot:(NSNumber *)counter {
        int n = [counter intValue];
        if (n > 0) {
            [self takeStill:videoConnection];
            [self performSelector:@selector(shoot:) 
                       withObject:[NSNumber numberWithInt:n - 1] 
                       afterDelay:<# your delay #>];
        }
    }
    

    [self shoot:[NSNumber numberWithInt:5]]开始拍摄。

    此外,您可以尝试多次拍摄而无需等待。 IIRC AVFoundation 将为您排队一些静止图像请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      • 2011-04-20
      相关资源
      最近更新 更多