简体   繁体   中英

AVCaptureVideoDataOutput Resolution

I am trying to specify output size to be 960x720 in video settings. However, it doesn't seem to work.

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]  

}  

Any other way to get the video data output in a custom lower resolution?

For sorry you should adhere to any of these presets

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

or use this library to scale it

https://github.com/NextLevel/NextLevelSessionExporter

And this is the relevant part

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM