AVAssetExportSession exportAsynchronously stuck/freeze/not starting

I attempt to export videos from Photo Library, but the export callback is never executed. I periodically check the progress of the export, and the progress is always zero.

AVAssetExportSession.Status always in waiting state


The code below works in 99.9% cases, but sometimes on some devices (absolutely randomly) it stops working, and only restart of the iPhone helps.

Code Block
import AVFoundation
let asset = AVAsset()
let outputURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("test.mov", isDirectory: false)
let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPreset1280x720)
exportSession?.outputFileType = .mov
exportSession?.outputURL = outputURL
try? FileManager.default.removeItem(at: outputURL)
exportSession?.exportAsynchronously(completionHandler: {
print("sometimes never calls")
})


It is an example of the output URL: file:///var/mobile/Containers/Data/Application/B9EB607F-8F6F-4E3B-A6C3-88B580B8839F/Documents/last.mov


P.S. Some other video apps also freeze on video export (Videoleap, PicsArt) but some video apps (Filto, InShot) continue working

Still same issue.

Same here. Restarting device fixes issue.

AVAssetExportSession exportAsynchronously stuck/freeze/not starting
 
 
Q