1

I am choosing videos using UIImagePickerController, then uploading the video to a web server using ASIHTTPRequest. However, videos that were shot with the iPhone held upside-down in landscape or portrait are inverted on the web server. When those uploaded videos are viewed on an iPhone, they are also scaled thy 75% or so vertically so that they appear squished.

Is there a way to determine the video orientation (including whether it was shot upside-down) of a video chosen using UIImagePickerController?

Also, is there a way to change the orientation of the video before uploading?

I'd also like to not allow uploads of video shot in portrait orientation.

Thanks

Alpinista
  • 3,751
  • 5
  • 35
  • 46

2 Answers2

1

Found the answer in anther post. AVAsset gives you two properties, [avAsset naturalSize] and [avAsset preferredTransform], that allow you to determine the video orientation.

Here's the related post:

How to detect (iPhone SDK) if a video file was recorded in portrait orientation, or landscape.

Community
  • 1
  • 1
Alpinista
  • 3,751
  • 5
  • 35
  • 46
  • 1
    thats fine we can found the rotation angle with this code... can we rotate video before uploading...have you found solution for rotation.. – Amit Battan Jan 23 '12 at 10:07
0

You can learn video portrait and assetOrientation with the func:

 static func orientationFromTransform(_ transform: CGAffineTransform) -> (orientation: UIImageOrientation, isPortrait: Bool) {
    var assetOrientation = UIImageOrientation.up
    var isPortrait = false
    if transform.a == 0 && transform.b == 1.0 && transform.c == -1.0 && transform.d == 0 {
      assetOrientation = .right
      isPortrait = true
    } else if transform.a == 0 && transform.b == -1.0 && transform.c == 1.0 && transform.d == 0 {
      assetOrientation = .left
      isPortrait = true
    } else if transform.a == 1.0 && transform.b == 0 && transform.c == 0 && transform.d == 1.0 {
      assetOrientation = .up
    } else if transform.a == -1.0 && transform.b == 0 && transform.c == 0 && transform.d == -1.0 {
      assetOrientation = .down
    }
    return (assetOrientation, isPortrait)
}

Sources: https://www.raywenderlich.com/5135-how-to-play-record-and-merge-videos-in-ios-and-swift

Yunus T.
  • 569
  • 7
  • 13