Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mooshee/6b9e35c53047373568f5 to your computer and use it in GitHub Desktop.
Save mooshee/6b9e35c53047373568f5 to your computer and use it in GitHub Desktop.

Revisions

  1. mooshee revised this gist Oct 29, 2015. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions AVAsset Video Orientation and Camera Position.swift
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    extension AVAsset {

    func videoOrientation() -> (orientation: UIInterfaceOrientation, device: AVCaptureDevicePosition) {
    var orientation = UIInterfaceOrientation.Unknown
    var device = AVCaptureDevicePosition.Unspecified
    var orientation: UIInterfaceOrientation = .Unknown
    var device: AVCaptureDevicePosition = .Unspecified

    let tracks = self.tracksWithMediaType(AVMediaTypeVideo)
    if tracks.count > 0 {
    let videoTrack = tracks.first!
    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) {
  2. mooshee renamed this gist Oct 29, 2015. 1 changed file with 0 additions and 0 deletions.
  3. mooshee renamed this gist Oct 29, 2015. 1 changed file with 0 additions and 0 deletions.
  4. mooshee renamed this gist Oct 29, 2015. 1 changed file with 0 additions and 0 deletions.
  5. mooshee created this gist Oct 29, 2015.
    52 changes: 52 additions & 0 deletions Extract AVAsset Orientation and Camera Position
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    extension AVAsset {

    func videoOrientation() -> (orientation: UIInterfaceOrientation, device: AVCaptureDevicePosition) {
    var orientation = UIInterfaceOrientation.Unknown
    var device = AVCaptureDevicePosition.Unspecified

    let tracks = self.tracksWithMediaType(AVMediaTypeVideo)
    if tracks.count > 0 {
    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)
    }
    }