密钥无效 - > AVCaptureVideoDataOutput(macOS)中的ProfileLevel

时间:2018-03-29 06:50:17

标签: swift macos avfoundation core-graphics core-media

我正在为AVCaptureVideoDataOutput添加密钥。当添加密钥AVVideoProfileLevelKey时,系统会抛出我 - >

  

无法设置(contentViewController)用户定义的检查属性   on(NSWindow):*** + [AVVideoOutputSettings   videoOutputSettingsWithVideoSettingsDictionary:]输出设置   字典包含一个或多个无效键:ProfileLevel

let captureSession = AVCaptureSession()
var videoCaptureOutput = AVCaptureVideoDataOutput()
videoCaptureOutput.videoSettings = [AVVideoCodecKey: AVVideoCodecType.h264,
                                        AVVideoWidthKey : 1280,
                                        AVVideoHeightKey : 720,
                                        AVVideoProfileLevelKey : AVVideoProfileLevelH264HighAutoLevel] as [String : Any]

密钥是AVVideoSettings.h的一部分,AVVideoCodecKeyAVVideoWidthKeyAVVideoHeightKey也是如此,但是我不清楚在哪里可以找到支持的密钥AVCaptureVideoDataOutput

2 个答案:

答案 0 :(得分:2)

键及其构造方法在(类型AVVideoCodecKey并跳转至定义)中进行了描述。在您的特定情况下,AVVideoProfileLevelKey : AVVideoProfileLevelH264HighAutoLevel应该放在另一个字典中,并且该字典应该设置为AVVideoCompressionPropertiesKey

let compressionSettings = [AVVideoProfileLevelKey: AVVideoProfileLevelH264HighAutoLevel]
videoCaptureOutput.videoSettings = [AVVideoCodecKey: AVVideoCodecType.h264,
                                    AVVideoWidthKey : 1280,
                                    AVVideoHeightKey : 720,
                                    AVVideoProfileLevelKey : compressionSettings]

希望这可以帮助任何人

答案 1 :(得分:0)

您的所有设置都不适合AVCaptureVideoDataOutput,它为您提供原始视频帧。您正在配置它,就好像它将帧编码为文件一样。因此,您的设置字典应与AVAssetWriterInput的{​​{1}}一起使用,或使用AVAssetWriter方法设置在AVCaptureMovieFileOutput上。