本文介绍了ios / iphone照片连拍模式api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在iPhone 5s上以最高分辨率(AVCaptureSessionPresetPhoto)拍摄多张照片。我尝试使用以下代码:

I'm trying to capture multiple photos on highest resolution(AVCaptureSessionPresetPhoto) on iPhone 5s. I tried using the following code:

    dispatch_semaphore_t sync = dispatch_semaphore_create(0);
while( [self isBurstModeEnabled] == YES )
                {
        [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
                             {

                                 if (imageSampleBuffer != NULL)
                                 {
                                     NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
                                     NSString *videoThumbPath = [NSString
                                                                 stringWithFormat:@"%@/img%d.png",
                                                                 burstFolderPath,
                                                                 index];

                                     [imageData writeToFile:videoThumbPath atomically:YES];
                                     if( 0 == index )
                                     {
                                         [self NSLogPrint:[NSString stringWithFormat:@"Created photo at %@",videoThumbPath]];
                                     }
                                 }
                                 dispatch_semaphore_signal(sync);
                             }];
    dispatch_semaphore_wait(sync, DISPATCH_TIME_FOREVER);
}

使用此代码我每秒可以获得大约2张照片,没有办法靠近本机相机应用程序的突发模式的性能。我究竟做错了什么?此外,我尝试使用上面的代码没有信号量,但在这种情况下,我有奇怪的行为,一些照片丢失(img0.png img1.png img3.png将存在,但img2.png将丢失)。使用第二种方法,性能会更好,但仍然不能与本机应用程序性能相媲美(在我的测试中,相机应用程序每秒会产生大约8.4张照片)。

Using this code I can get about 2 photos per second, no way near the performance of burst mode of the native camera app. What am I doing wrong? Also I tried using the code above without the semaphore, but in that case I was having weird behavior, some photos were missing(img0.png img1.png img3.png would be present but img2.png would be missing). Using the second method the performance would be better but still not on par with the native app performance(in my tests the camera app would make about 8.4 photos per second).

推荐答案

captureStillImageAsynchronouslyFromConnection:completionHandler:不是,我相信Apple正在使用它的突发模式。

captureStillImageAsynchronouslyFromConnection:completionHandler: isn't, I believe, what Apple is using for its burst mode.

相反,Apple以全分辨率*(#)支持视频帧(5s支持)。方法如下:

Instead, Apple is* grabbing video frames at full resolution (which is supported by the 5s). Here's how:

AVCaptureDevice将 activeFormat 设置为完整的传感器分辨率,然后你抓取并处理每帧10帧第二个来自 AVCaptureVideoDataOutputSampleBufferDelegate captureOutput:didOutputSampleBuffer:fromConnection:,为每次抓取帧发出快门声。

The AVCaptureDevice has its activeFormat set to full sensor resolution, then you grab and process 10 frames per second from AVCaptureVideoDataOutputSampleBufferDelegate's captureOutput:didOutputSampleBuffer:fromConnection:, firing off a shutter sound for each frame grab.

对于不支持完全传感器尺寸分辨率的视频的设备,您需要进行回退(低分辨率图像或较慢的突发模式) - 和/或如果你想支持早于iOS 7.x的任何东西。

You'll need to have a fall-back (either lower-resolution images or a slower burst mode) for devices that don't support video at the full sensor-size resolution—and/or if you want to support anything older than iOS 7.x.

请注意,你不能同时使用多个 captureStillImageAsynchronouslyFromConnection :completionHandler:没有一些非常意外的结果。这就是你应该从前一个 completionHandler 调用每个迭代的原因(实质上,这是你的信号量正在做的事情)。此外,您可能希望从PNG切换为突发镜头的文件格式 - 它保存得非常慢并且需要大量系统资源 - 堆叠15或20个PNG可能会让您感到非常悲伤!

Note that you can't have multiple concurrent usage of captureStillImageAsynchronouslyFromConnection:completionHandler: without some extremely unexpected results. This is why you should call each iteration from the previous one's completionHandler (which, in essence, is what your semaphore is doing). Also, you may wish to switch from PNG as your file format for burst shots—it saves very slowly and requires a lot of system resource—stacking up 15 or 20 PNGs could cause you some serious grief!

* 可能这样做,因为它当然可以使用私有API来实现相同的最终结果。

这篇关于ios / iphone照片连拍模式api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 06:54