用于在macOS 10.15上捕获图像的Swift命令行工具

用于在macOS 10.15上捕获图像的Swift命令行工具,swift,macos,avfoundation,macos-catalina,Swift,Macos,Avfoundation,Macos Catalina,我需要一个可执行的命令行工具,捕捉与Swift和AVFoundation的图像 我收到了工作许可请求,并看到相机的led灯亮起,但我没有达到照片输出(\uU2DidFinishProcessingPhoto:error:)委托功能以获取照片本身(或可能的错误…) 我错过了什么 导入参数分析器 进口AVF基金会 最终类ImageSnaper:NSObject、ParsableCommand、AVCapturePhotoCaptureDelegate{ @参数var imagePath:字符串 fu

我需要一个可执行的命令行工具,捕捉与Swift和AVFoundation的图像

我收到了工作许可请求,并看到相机的led灯亮起,但我没有达到
照片输出(\uU2DidFinishProcessingPhoto:error:)
委托功能以获取照片本身(或可能的错误…)

我错过了什么

导入参数分析器
进口AVF基金会
最终类ImageSnaper:NSObject、ParsableCommand、AVCapturePhotoCaptureDelegate{
@参数var imagePath:字符串
func run()抛出{
打印(“”)
将图像保存到\(imagePath)。
""")
ImageSnaperDelegate().snap()
}
}
类ImageSnaperDelegate:NSObject,AVCapturePhotoCaptureDelegate{
let session=AVCaptureSession()
func snap(){
session.sessionPreset=AVCaptureSession.Preset.photo
让设备=AVCaptureDevice.default(对于:。视频)!
让输入=try!AVCaptureDeviceInput(设备:设备)
if session.canAddInput(输入){
会话.添加输入(输入)
}否则{
打印(“无法添加输入…”)
法塔莱罗()
}
let output=AVCapturePhotoOutput()
if session.canAddOutput(输出){
session.addOutput(输出)
}否则{
打印(“无法添加输出…”)
}
let settings=AVCapturePhotoSettings(格式:[
AVVideoCodeKey:AVVideoCodeType.jpeg
])
会议.启动耳轴()
output.capturePhoto(带:设置,代表:自身)
}
func photoOutput(uu输出:AVCapturePhotoOutput,didFinishProcessingPhoto照片:AVCapturePhoto,错误:error?){
如果let error=error{
打印(“didFinishProcessingPhoto中的错误:\(Error.localizedDescription)”)
}否则{
打印(“照片快照…”)
session.stopRunning()
}
}
}
ImageSnapper.main()
控制台输出如下:

Saving an image to ~/Desktop/image.jpeg.
2020-09-26 08:48:48.588431+0200 SwiftImageSnap2[2620:74787] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x101831bb0> 30010C1C-93BF-11D8-8B5B-000A95AF9C6A
2020-09-26 08:48:48.726674+0200 SwiftImageSnap2[2620:74787] [] CMIOHardware.cpp:917:CMIODeviceStopStream the System is exiting
2020-09-26 08:48:48.726909+0200 SwiftImageSnap2[2620:74787] [] CMIOHardware.cpp:1332:CMIOStreamCopyBufferQueue the System is exiting
2020-09-26 08:48:48.727138+0200 SwiftImageSnap2[2620:74787] [] CMIOHardware.cpp:333:CMIOObjectGetPropertyData the System is exiting
2020-09-26 08:48:48.727690+0200 SwiftImageSnap2[2620:74787] [] CMIO_DALA_System.cpp:264:GetPropertyData error 1970171760 (unop) getting property selector (inot) scope (glob) element 0
2020-09-26 08:48:48.728841+0200 SwiftImageSnap2[2620:74787] [] CMIOHardware.cpp:333:CMIOObjectGetPropertyData the System is exiting
2020-09-26 08:48:48.729067+0200 SwiftImageSnap2[2620:74787] [] CMIO_DALA_System.cpp:264:GetPropertyData error 1970171760 (unop) getting property selector (inot) scope (glob) element 0
Program ended with exit code: 0
将图像保存到~/Desktop/image.jpeg。
2020-09-26 08:48:48.588431+020 SwiftImageSnap2[2620:74787][plugin]工厂附加说明:没有注册id为30010C1C-93BF-11D8-8B5B-000A95AF9C6A的工厂
2020-09-26 08:48:48.726674+020 SwiftImageSnap2[2620:74787][]CMIOHardware.cpp:917:CMIODeviceStopStream系统正在退出
2020-09-26 08:48:48.726909+020 SwiftImageSnap2[2620:74787][]CMIOHardware.cpp:1332:CMIOStreamCopyBufferQueue系统正在退出
2020-09-26 08:48:48.727138+020 SwiftImageSnap2[2620:74787][]CMIOHardware.cpp:333:CMIOObjectGetPropertyData系统正在退出
2020-09-26 08:48:48.727690+020 SwiftImageSnap2[2620:74787][]CMIO_DALA_系统cpp:264:GetPropertyData错误1970171760(unop)获取属性选择器(inot)作用域(glob)元素0
2020-09-26 08:48:48.728841+020 SwiftImageSnap2[2620:74787][]CMIOHardware.cpp:333:CMIOObjectGetPropertyData系统正在退出
2020-09-26 08:48:48.729067+020 SwiftImageSnap2[2620:74787][]CMIO_DALA_系统cpp:264:GetPropertyData错误1970171760(unop)获取属性选择器(inot)作用域(glob)元素0
程序以退出代码结束:0