我不太清楚如何处理前置摄像头视频捕捉方向。当捕捉视频和照片时,我已经处理了后置摄像头的所有旋转,并且处理了拍摄照片时前置摄像头的所有旋转,以及将捕获的视频和图片保存为正确的方向,除了前置摄像头视频捕捉之外。
第一个问题是无论是横屏还是竖屏模式下,视频都没有以正确的方向保存。第二个问题是保存的视频是镜像的。虽然我知道如何处理使用前置摄像头拍照的镜像效果,但我不确定如何处理视频。
我在尝试寻找有关此问题的具体信息时遇到了很多麻烦,并未成功。如果有人能指导我指向解决此特定问题的线程,那就太好了。
无论如何,这是被调用的处理设备方向变化时处理视频方向的方法。如果正在使用前置摄像头,我不确定应该添加什么代码。
/**************************************************************************
DEVICE ORIENTATION DID CHANGE
**************************************************************************/
func deviceOrientationDidChange() {
println("DEVICE ORIENTATION DID CHANGE CALLED")
let orientation: UIDeviceOrientation = UIDevice.currentDevice().orientation
//------ IGNORE THESE ORIENTATIONS ------
if orientation == UIDeviceOrientation.FaceUp || orientation == UIDeviceOrientation.FaceDown || orientation == UIDeviceOrientation.Unknown || orientation == UIDeviceOrientation.PortraitUpsideDown || self.currentOrientation == orientation {
println("device orientation does not need to change --- returning...")
return
}
self.currentOrientation = orientation
//------ APPLY A ROTATION USING THE STANDARD ROTATION TRANSFORMATION MATRIX in R3 ------
/*
x y z
--- ---
x | cosø sinø 0 |
y | -sinø consø 0 |
z | 0 0 1 |
--- ---
*/
//----- PERFORM BUTTON AND VIDEO DATA BUFFER ROTATIONS ------
switch orientation {
case UIDeviceOrientation.Portrait:
rotateButtons(self.degrees0)
if self.usingFrontCamera == true {
}
else {
}
println("Device Orientation Portrait")
break
case UIDeviceOrientation.LandscapeLeft:
println("Device Orientation LandScapeLeft")
rotateButtons(self.degrees90)
if self.usingFrontCamera == true {
println("Using front camera, rotation in landscape left")
// if let connection = self.captureConnection {
//
// connection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight
//
// println("Capture connection Orientation is LandScape Right")
// }
// else {
//
// println("Capture connection is nil, could not change video orientation")
// }
}
else {
if let connection = self.captureConnection {
connection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight
println("Capture connection Orientation is LandScape Right")
}
else {
println("Capture connection is nil, could not change video orientation")
}
}
break
case UIDeviceOrientation.LandscapeRight:
println("Device Orientation LandscapeRight")
rotateButtons(-self.degrees90)
if self.usingFrontCamera == true {
println("Using front camera, rotation in landscape right")
// if let connection = self.captureConnection {
//
// connection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight
//
// println("Capture connection Orientation is LandScape Left")
// }
// else {
//
// println("Capture connection is nil, could not change video orientation")
// }
}
else {
if let connection = self.captureConnection {
connection.videoOrientation = AVCaptureVideoOrientation.LandscapeLeft
println("Capture connection Orientation is LandScape Left")
}
else {
println("Capture connection is nil, could not change video orientation")
}
}
break
default:
break
}
}
self.videoOutput?.connection(with: .video)?.isVideoMirrored = true
来获取连接。 - Kesong Xie