Solid
Solid

Reputation: 307

How to detect if video is Landscape/portrait when fetched from PHAsset?

I am fetching videos from PHAsset so user can choose the video and import to perform edit. But user should be only able to select video with Landscape orientation, if user select portrait video, she/he would get alert message saying that its portrait video and hence can not import to edit.

One way to do this is creating AVAsset from URL of PHFetchResults, and then checking a preferedTransform, but that would be very costly operation to do right?

Is there a way to do this without creating AVasset?

Upvotes: 2

Views: 2450

Answers (1)

Mohamed Jaleel Nazir
Mohamed Jaleel Nazir

Reputation: 5821

https://developer.apple.com/library/ios/documentation/Photos/Reference/PHAsset_Class/

var pixelWidth: Int { get }

var pixelHeight: Int { get }

The width and height, in pixels, of the asset’s image or video data. (read-only)

If the asset’s content has been edited, this property describes the size of the current version of the asset. Availability iOS (8.0 and later)

if asset!.pixelHeight > asset!.pixelWidth {
 // will be portrait video or Image
}

Available in iOS 8.0 and later.

Upvotes: 5

Related Questions