【问题标题】:AVCaptureDevice - iphone/ipad as video sourceAVCaptureDevice - iphone/ipad 作为视频源
【发布时间】:2015-02-27 23:06:45
【问题描述】:

当通过闪电电缆连接时,可以使用 AVCaptureDevice(objective-c 或 Swift)访问 iOS 设备作为相机源,就像 Quicktime 为 OSX Yosemite 所做的那样?

Quicktime select camera source image

如果没有,有没有其他方法可以捕捉到它?

我正在使用 AVCaptureDevice.devices()(快速),但它只列出了内置的 Mac 摄像头和麦克风。

【问题讨论】:

  • 迈克尔,我想知道如何在 Objective-C 或 Swift 中做到这一点...不是用户问题...
  • 很抱歉。我一定是在分区。

标签: objective-c macos swift


【解决方案1】:

在查看 a presentation on WWDC Apple 宣布此功能后找到了解决方案(感谢 Chris Adamson) - 快进到 4:09。

需要先设置以下 CMI 属性,然后 AVCaptureDevice 才能将 iOS 设备检测为摄像头/捕获设备(Swift 中的示例):

var prop : CMIOObjectPropertyAddress = CMIOObjectPropertyAddress(
        mSelector: CMIOObjectPropertySelector(kCMIOHardwarePropertyAllowScreenCaptureDevices),
        mScope: CMIOObjectPropertyScope(kCMIOObjectPropertyScopeGlobal),
        mElement: CMIOObjectPropertyElement(kCMIOObjectPropertyElementMaster))
    
var allow:UInt32 = 1
    
CMIOObjectSetPropertyData( CMIOObjectID(kCMIOObjectSystemObject),
        &prop,
        0,
        nil,
        UInt32(sizeofValue(allow)),
        &allow)

完成后(例如在您的 AppDelegate 中),可以完成观察者的标准注册,iOS 相机将显示在可用设备列表中

// register for notifications when a new device is connected
notifications.registerObserver(AVCaptureSessionDidStartRunningNotification, forObject: session, block: {note in
        
    var devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeMuxed)
                +  AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) as! [AVCaptureDevice]

    for device in self.devices {
        if device.modelID == "iOS Device" {
            // device is your AVCaptureDevice... use it as usual
        }
    }
})

【讨论】:

  • ??你在问什么@AbdulYasin??
  • @Gonçalo Borrêga:我的问题是我可以使用 iPhone 作为在手表上显示实时相机预览的来源。像我可以与 HomeKit 一起使用的东西。我的目标是直接从配对的 iPhone 设备在手表上显示相机预览。
  • @AbdulYasin 这是关于将 iPhone 用作连接到 Mac 的源摄像头(并在 Mac 中显示 iphone 上的内容)。要在手表上显示视频/图像,必须遵循不同的方法(甚至不知道手表框架是否支持 AV* 类
  • 如何为 Objective c 应用程序捕获视频文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-04
  • 1970-01-01
  • 2015-06-23
  • 2012-01-09
  • 2012-06-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多