|
| 1 | + @available(iOS 11.0, *) |
| 2 | + func compressVid(videoURL: URL, timeStamp: Double, thumbnail: UIImage, caption: String) { |
| 3 | + // Get source video |
| 4 | + let videoToCompress = videoURL//any valid URL pointing device storage |
| 5 | + print("method called") |
| 6 | + // Declare destination path and remove anything exists in it |
| 7 | + let destinationPath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("compressed.mp4") |
| 8 | + try? FileManager.default.removeItem(at: destinationPath) |
| 9 | + |
| 10 | + print(destinationPath, "74382190478321947302914789302173891742894032430912") |
| 11 | + |
| 12 | + // Compress |
| 13 | + compressh264VideoInBackground( |
| 14 | + videoToCompress: videoToCompress, |
| 15 | + destinationPath: destinationPath, |
| 16 | + size: nil, |
| 17 | + compressionTransform: .keepSame, |
| 18 | + compressionConfig: .defaultConfig, |
| 19 | + completionHandler: { [weak self] path in |
| 20 | + print("---------------------------") |
| 21 | + print("Success", path) |
| 22 | + print("---------------------------") |
| 23 | + print("Original video size:") |
| 24 | + |
| 25 | + print("---------------------------") |
| 26 | +// print(URL(withpa: path.absoluteString), " This is teh compressed video url") |
| 27 | + DispatchQueue.main.async { |
| 28 | + let newUserTakenVid = InterimMediaObject(videoURL: URL(fileURLWithPath: path.path), timeStamp: timeStamp, caption: caption, thumbnail: thumbnail) |
| 29 | + // media.append(newUserTakenVid) //has been replaced by below |
| 30 | + GlobalSharedData.shared.arrayOfCurrentCreateMedia.append(newUserTakenVid) //new may 11, 2019 implenetation of option 1 (realtime) global class stuff... |
| 31 | + self!.numberMediaIndicatorLabel.text = "\(GlobalSharedData.shared.arrayOfCurrentCreateMedia.count)" //new impletnation of global clas may 11, 2019 |
| 32 | + } |
| 33 | + |
| 34 | + }, |
| 35 | + errorHandler: { e in |
| 36 | + print("---------------------------") |
| 37 | + print("Error: ", e) |
| 38 | + print("---------------------------") |
| 39 | + }, |
| 40 | + cancelHandler: { |
| 41 | + print("---------------------------") |
| 42 | + print("Cancel") |
| 43 | + print("---------------------------") |
| 44 | + } |
| 45 | + ) |
| 46 | + |
| 47 | + // To cancel compression, set cancel flag to true and wait for handler invoke |
| 48 | +// cancelable.cancel = true |
| 49 | + |
| 50 | + } |
0 commit comments