Reputation: 11
i have writen following code to export my video with an overlay layer but for one minute video it is taking a lot of time to export. How can i reduce the time to export the video in less time without reducing the quality.
i have tried this
func exportVideo(composition: AVMutableComposition, videoComposition: AVMutableVideoComposition, onComplete: @escaping (URL?) -> Void){
guard let export = AVAssetExportSession(
asset: composition,
presetName: AVAssetExportPresetMediumQuality)
else {
print("Cannot create export session.")
onComplete(nil)
return
}
let videoName = UUID().uuidString
let exportURL = URL(fileURLWithPath: NSTemporaryDirectory())
.appendingPathComponent(videoName)
.appendingPathExtension("mov")
export.videoComposition = videoComposition
export.outputFileType = .mov
export.outputURL = exportURL
export.exportAsynchronously {
DispatchQueue.main.async {
switch export.status {
case .completed:
onComplete(exportURL)
default:
print("Something went wrong during export.")
print(export.error ?? "unknown error")
onComplete(nil)
}
}
}
}
Upvotes: 1
Views: 45