Last active
August 10, 2016 09:04
-
-
Save sanghapark/8e8b748c2cda05bca6bbeca3afd4d4ea to your computer and use it in GitHub Desktop.
get video orientaiton and position (back or front camera)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension AVAsset { | |
func videoOrientation() -> (orientation: UIInterfaceOrientation, device: AVCaptureDevicePosition) { | |
var orientation: UIInterfaceOrientation = .Unknown | |
var device: AVCaptureDevicePosition = .Unspecified | |
let tracks :[AVAssetTrack] = self.tracksWithMediaType(AVMediaTypeVideo) | |
if let videoTrack = tracks.first { | |
let t = videoTrack.preferredTransform | |
if (t.a == 0 && t.b == 1.0 && t.d == 0) { | |
orientation = .Portrait | |
if t.c == 1.0 { | |
device = .Front | |
} else if t.c == -1.0 { | |
device = .Back | |
} | |
} | |
else if (t.a == 0 && t.b == -1.0 && t.d == 0) { | |
orientation = .PortraitUpsideDown | |
if t.c == -1.0 { | |
device = .Front | |
} else if t.c == 1.0 { | |
device = .Back | |
} | |
} | |
else if (t.a == 1.0 && t.b == 0 && t.c == 0) { | |
orientation = .LandscapeRight | |
if t.d == -1.0 { | |
device = .Front | |
} else if t.d == 1.0 { | |
device = .Back | |
} | |
} | |
else if (t.a == -1.0 && t.b == 0 && t.c == 0) { | |
orientation = .LandscapeLeft | |
if t.d == 1.0 { | |
device = .Front | |
} else if t.d == -1.0 { | |
device = .Back | |
} | |
} | |
} | |
return (orientation, device) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment