Created
February 4, 2020 08:10
-
-
Save Denismih/a1a193528241d0771cbfa1ea0e663645 to your computer and use it in GitHub Desktop.
getVideoResolution
This file contains 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
var mediaAspectRatio: Double! // <- here will be set aspect ratio for video with url | |
func initAspectRatioOfVideo(with fileURL: URL) { | |
let resolution = resolutionForLocalVideo(url: fileURL) | |
guard let width = resolution?.width, let height = resolution?.height else { | |
return | |
} | |
mediaAspectRatio = Double(height / width) | |
} | |
private func resolutionForLocalVideo(url: URL) -> CGSize? { | |
guard let track = AVURLAsset(url: url).tracks(withMediaType: AVMediaTypeVideo).first else { return nil } | |
let size = track.naturalSize.applying(track.preferredTransform) | |
return CGSize(width: fabs(size.width), height: fabs(size.height)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment