美文网首页
如何设置AVFoundation输出的照片为Portrait

如何设置AVFoundation输出的照片为Portrait

作者: 南国青天 | 来源:发表于2019-01-02 14:53 被阅读2次
            let device = AVCaptureDevice.devices().filter { $0.hasMediaType(AVMediaType.video) && $0.position == .front }.first!
            let input:AVCaptureDeviceInput
            do {
                input = try AVCaptureDeviceInput(device: device)
            } catch {
                return
            }

            let output = AVCaptureVideoDataOutput()
            captureSession = AVCaptureSession()
            captureSession?.addInput(input)
            //先将输出添加到到captureSesssion,然后才能设置connection, 否则输出照片无法Portrait。
            captureSession?.addOutput(output) 
            output.connection(with: .video)?.videoOrientation = .portrait
            output.connection(with: .video)?.isVideoMirrored = true

            let queue = DispatchQueue(label: "cameraQueue")
            output.setSampleBufferDelegate(self, queue: queue)
            output.videoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable as! String: kCVPixelFormatType_32BGRA]
            captureSession?.startRunning()

相关文章

网友评论

      本文标题:如何设置AVFoundation输出的照片为Portrait

      本文链接:https://www.haomeiwen.com/subject/bcyzlqtx.html