AVFoundation视频方向

时间:2018-08-02 19:48:55

标签: ios camera avfoundation avcapturesession

我注意到,在iOS设备上,默认情况下,视频设备的videoOrientation的{​​{1}}属性对于前置摄像头是AVCaptureConnection,对于后置摄像头是landscapeLeft。同时,两种情况下的实际像素数据都定向为landscapeRight。据我所知,这不是任何错误,因为我在Apple的sample中找到了以下代码。

landscapeLeft

extension PreviewMetalView.Rotation { init?(with interfaceOrientation: UIInterfaceOrientation, videoOrientation: AVCaptureVideoOrientation, cameraPosition: AVCaptureDevice.Position) { /* Calculate the rotation between the videoOrientation and the interfaceOrientation. The direction of the rotation depends upon the camera position. */ switch videoOrientation { case .portrait: switch interfaceOrientation { case .landscapeRight: if cameraPosition == .front { self = .rotate90Degrees } else { self = .rotate270Degrees } case .landscapeLeft: if cameraPosition == .front { self = .rotate270Degrees } else { self = .rotate90Degrees } case .portrait: self = .rotate0Degrees case .portraitUpsideDown: self = .rotate180Degrees default: return nil } case .portraitUpsideDown: switch interfaceOrientation { case .landscapeRight: if cameraPosition == .front { self = .rotate270Degrees } else { self = .rotate90Degrees } case .landscapeLeft: if cameraPosition == .front { self = .rotate90Degrees } else { self = .rotate270Degrees } case .portrait: self = .rotate180Degrees case .portraitUpsideDown: self = .rotate0Degrees default: return nil } case .landscapeRight: switch interfaceOrientation { case .landscapeRight: self = .rotate0Degrees case .landscapeLeft: self = .rotate180Degrees case .portrait: if cameraPosition == .front { self = .rotate270Degrees } else { self = .rotate90Degrees } case .portraitUpsideDown: if cameraPosition == .front { self = .rotate90Degrees } else { self = .rotate270Degrees } default: return nil } case .landscapeLeft: switch interfaceOrientation { case .landscapeLeft: self = .rotate0Degrees case .landscapeRight: self = .rotate180Degrees case .portrait: if cameraPosition == .front { self = .rotate90Degrees } else { self = .rotate270Degrees } case .portraitUpsideDown: if cameraPosition == .front { self = .rotate270Degrees } else { self = .rotate90Degrees } default: return nil } } } } 在前后摄像头上的工作方式似乎有所不同,我在文档或网络上找不到任何相关信息。有人知道财产如此奇怪的行为的原因吗?

0 个答案:

没有答案