AVCaptureVideoDataOutput分辨率

时间:2019-04-06 16:03:01

标签: ios swift xcode avfoundation avcapturesession

我正在尝试在视频设置中将输出大小指定为960x720。但是,它似乎不起作用。

self.videoDataOutput = AVCaptureVideoDataOutput()  
if self.session.canAddOutput(self.videoDataOutput!) {  
    self.session.addOutput(videoDataOutput!)   
    self.videoDataOutput!.videoSettings = [kCVPixelBufferPixelFormatTypeKey: Int(kCVPixelFormatType_32BGRA),  
                                           kCVPixelBufferHeightKey: 960,  
                                           kCVPixelBufferWidthKey: 720] as [String : Any]  

}  

还有其他以定制的较低分辨率获取视频数据输出的方法吗?

1 个答案:

答案 0 :(得分:1)

对不起,您应该遵循以下任何预设

https://developer.apple.com/documentation/avfoundation/avcapturesession/preset

或使用此库对其进行缩放

https://github.com/NextLevel/NextLevelSessionExporter

这是相关的部分

let exporter = NextLevelSessionExporter(withAsset: asset) 
exporter.videoOutputConfiguration = [
    AVVideoCodecKey: AVVideoCodec.h264,
    AVVideoWidthKey: NSNumber(integerLiteral: 720),
    AVVideoHeightKey: NSNumber(integerLiteral: 960),
    AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill,
    AVVideoCompressionPropertiesKey: compressionDict
]