Video Saving in the wrong orientation AVCaptureSession

后端 未结 4 1010
情书的邮戳
情书的邮戳 2020-12-31 07:13

I\'m trying to record a video (without displaying the camera) and save it. But the video being saved is not saving in the right orientation. I\'ve tried forcing the UIViewCo

4条回答
  •  天涯浪人
    2020-12-31 07:55

    **

    Try changing its orientation just before starting recording.

    **

        if let videoConnection = fileOutput.connection(with: .video) {
    
        let newOrientation: AVCaptureVideoOrientation
        switch UIDevice.current.orientation {
        case .portrait:
            newOrientation = .portrait
        case .portraitUpsideDown:
            newOrientation = .portraitUpsideDown
        case .landscapeLeft:
            newOrientation = .landscapeRight
        case .landscapeRight:
            newOrientation = .landscapeLeft
        default :
            newOrientation = .portrait
        }
        videoConnection.videoOrientation = newOrientation
        self.fileOutput.startRecording(to: URL(fileURLWithPath: filePath), recordingDelegate: self)
    }
    

    where,

    var fileOutput : AVCaptureMovieFileOutput!
    

提交回复
热议问题