Even when I don't apply any filters the performance of AVAssetExportSession exportAsynchronously is very very bad. It takes more than 10 seconds or so to export a 26 second video. How can I fix that?
let avPlayerItem = AVPlayerItem(asset: video)
avVideoComposition = AVVideoComposition(asset: avPlayerItem.asset, applyingCIFiltersWithHandler: { request in
request.finish(with: request.sourceImage, context: nil)
})
avPlayerItem.videoComposition = avVideoComposition
// -----------
func exportFilterVideo(videoComposition:AVVideoComposition , completion: @escaping
(_ outputURL : NSURL?) -> ()) {
let exportSession = AVAssetExportSession(asset: self, presetName: AVAssetExportPresetHighestQuality)!
let croppedOutputFileUrl = URL( fileURLWithPath: NSTemporaryDirectory() + NSUUID().uuidString + ".mov")
exportSession.outputURL = croppedOutputFileUrl
exportSession.outputFileType = AVFileType.mov
exportSession.videoComposition = videoComposition
exportSession.exportAsynchronously(completionHandler: {
guard exportSession.status != .failed else {
completion(nil)
return
}
if exportSession.status == .completed {
DispatchQueue.main.async(execute: {
completion(croppedOutputFileUrl as NSURL)
})
}
else {
completion(nil)
}
})
}
even when I use AVAssetExportPresetLowQuality
it does not help!