Snapchat刚刚发布了一个桌面应用(link),该应用旨在在系统中创建视频设备,供任何视频应用(例如Skype,Google Hangouts,苹果公司的Photobooth甚至OBS)用于实时流传输。它在其他应用中效果很好,因为它们似乎可以与“ FaceTime HD摄像头”一起检测摄像头设备。
因此,我尝试使用Xcode制作OSX应用程序。希望我能得到视频提要。我使用的是我从此github取得的以下代码示例:AcceCamera Demo
该应用程序非常适合显示“ FacetimeHD摄像机”的提要,但在选择SnapCam设备时不起作用(因为它没有显示任何内容)。
这是代码(您也可以使用上面的链接,与此唯一的区别是选择SnapCam设备):
import Cocoa
import AVFoundation
class ViewController: NSViewController {
@IBOutlet weak var camera: NSView!
let captureSession = AVCaptureSession()
var captureDevice : AVCaptureDevice?
var previewLayer : AVCaptureVideoPreviewLayer?
override func viewDidLoad() {
super.viewDidLoad()
camera.layer = CALayer()
// Do any additional setup after loading the view, typically from a nib.
captureSession.sessionPreset = AVCaptureSessionPresetLow
// Get all audio and video devices on this machine
let devices = AVCaptureDevice.devices()
// Find the FaceTime HD camera object
for device in devices! {
// print(device)
// Camera object found and assign it to captureDevice
if ((device as AnyObject).hasMediaType(AVMediaTypeVideo)) {
print(device)
let d = device as? AVCaptureDevice
print("\(d?.manufacturer)")
if(d?.manufacturer == "SnapVendor"){
captureDevice = device as? AVCaptureDevice
break;
}
}
}
if captureDevice != nil {
do {
try captureSession.addInput(AVCaptureDeviceInput(device: captureDevice))
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.frame = (self.camera.layer?.frame)!
// Add previewLayer into custom view
self.camera.layer?.addSublayer(previewLayer!)
// Start camera
captureSession.startRunning()
} catch {
print(AVCaptureSessionErrorKey.description)
}
}
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
我觉得很奇怪,OBS等其他应用程序在接收提要时没有问题。