Created
February 4, 2020 08:10
Revisions
-
Denismih created this gist
Feb 4, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ 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)) }