-
Notifications
You must be signed in to change notification settings - Fork 2
/
AVAsset.swift
34 lines (30 loc) · 915 Bytes
/
AVAsset.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// AVAsset.swift
// VAVideoCompressor
//
// Created by Anton Vodolazkyi on 29.07.2018.
// Copyright © 2018 Anton Vodolazkyi. All rights reserved.
//
import AVFoundation
import UIKit
extension AVAsset {
func videoSize() -> CGSize {
let visual = AVMediaCharacteristic.visual
let vTrack = tracks(withMediaCharacteristic: visual)[0]
var error: NSError? = nil
let keyPath = #keyPath(AVAssetTrack.naturalSize)
if vTrack.statusOfValue(forKey: keyPath, error: &error) == .loaded {
return vTrack.orientationBasedSize
} else {
var size = CGSize()
let dg = DispatchGroup()
dg.enter()
vTrack.loadValuesAsynchronously(forKeys: [keyPath]) {
size = vTrack.orientationBasedSize
dg.leave()
}
dg.wait()
return size
}
}
}