【问题标题】:Issue with captureStillImageAsynchronouslyFromConnection for Back camera后置摄像头的 captureStillImageAsynchronouslyFromConnection 问题
【发布时间】:2015-03-17 12:10:57
【问题描述】:
let VideoDevice = CameraWithPosition(AVCaptureDevicePosition.Back) // not working

let VideoDevice = CameraWithPosition(AVCaptureDevicePosition.Front) // working

if let stillOutput = self.stillImageOutput {

                if let videoConnection = stillOutput.connectionWithMediaType(AVMediaTypeVideo)
                {
                    println("stillOutput \(stillOutput)")

                        stillOutput.captureStillImageAsynchronouslyFromConnection(videoConnection){
                            (imageSampleBuffer : CMSampleBuffer!, _) in

                            println("imageSampleBuffer \(imageSampleBuffer)") //prints nil for back camera, works for front camera

...more code

我可以从前置摄像头拍摄图像,但相同的过程不适用于我的 Iphone 后置摄像头,两个摄像头是否有任何不同的设置?

后置摄像头接收 imageSampleBuffer 为 nil..

错误日志:

错误域=AVFoundationErrorDomain Code=-11800“操作无法完成” UserInfo=0x1704682c0 {NSUnderlyingError=0x170255d20“操作无法完成。(OSStatus错误-16803。)”,NSLocalizedFailureReason=发生未知错误(-16803), NSLocalizedDescription=操作无法完成}

【问题讨论】:

  • 你的问题解决了吗?

标签: ios iphone swift avcapturesession


【解决方案1】:

试试

NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in videoDevices)
{
    NSLog(device.description);
}

查看您是否收到这样的消息:

AVCaptureFigVideoDevice: hex[Back Camera][com.apple.avfoundation.avcapturedevice.built-in_video:0]

当我无法使用相机并且它不会出现在设备列表中时,我遇到了问题。然后我注意到即使是标准的相机应用程序也无法工作。所以我只是重新加载了我的 iPad,它解决了我的问题。我认为在测试我的应用程序期间,我设法以某种方式更改了一些重要的东西。

【讨论】:

  • 奇怪.. 但不是我的情况
【解决方案2】:

检查 “...更多代码”

前置摄像头将更快地返回图像,因此如果您在 captureStillImageAsynchronouslyFromConnection 之后直接停止预览或对 videoConnection 进行其他更改,它可能适用于前置摄像头,但不适用于后置摄像头。

【讨论】:

    【解决方案3】:

    我的解决方案: captureStillImageAsynchronouslyFromConnectioncapturePhoto 方法上。

    添加:

    if(!CMSampleBufferIsValid(imageSampleBuffer))
    {
          [self capturePhoto];
          return;
    }
    

    方法好像是这样的:

        - (void) capturePhoto {
    
            ...SOME CODE...
    
            [_stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
             {
                 if(!CMSampleBufferIsValid(imageSampleBuffer))//Check if capture failed
                 {
                     [self capturePhoto];
                     return;
                 }
    
                 ...SOME CODE...
    
             }];
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多