I'm working on adding video recording to an app using AVFoundation. I managed to record the video and then display it, but then I realized that (unlike in the preview) front-camera videos aren't mirrored along the vertical axis. It seems like this is the standard behavior but I would like the video to look like the preview. I believe that CGAffineTransform
can do this but I'm not sure how to apply it to the video.
This is what I had so far:
extension CameraViewController: AVCaptureFileOutputRecordingDelegate {
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
guard error != nil else {
print("Error recording movie: \(error!.localizedDescription)")
return
}
if self.currentCameraPosition == .front {
mirrorVideo(outputFileURL)
}
performSegue(withIdentifier: "ShowVideo", sender: outputFileURL)
}
func mirrorVideo(_ outputFileURL: URL){
var transform: CGAffineTransform = CGAffineTransform(scaleX: -1.0, y: 1.0)
transform = transform.rotated(by: CGFloat(Double.pi/2))
// Apply transform
}
}