2012-01-03 10 views
1

AVFoundationフレームワークを使用してバーストモード(急速に5ショット)を実装したいが、難しかったです。iPhoneとAVFoundationを使用したバーストモード

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 
}]; 
} 

このように1つの画像を撮影すると、正常に動作します。おそらく、スレッドをスリープさせると、nImagesがすべて取得されるまで完了ハンドラが実行されず、その結果、imageSampleBufferはNULLになります。これを処理する正しい方法は何ですか? [self shoot:[NSNumber numberWithInt:5]]で撮影

- (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 #>]; 
    } 
} 

スタート:

答えて

2

は、このアプローチを試してみてください。

また、待たずに数回試してみることもできます。 IIRC AVFoundationはあなたのためにいくつかの静止画要求を待ち行列に入れます。

関連する問題