Gizmodo
Gizmodo

Reputation: 3212

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?

Upvotes: 1

Views: 2032

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100549

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
]

Upvotes: 1

Related Questions