我正在尝试使用AVAssetExportSession导出旋转的视频,并希望在单击按钮时暂停并恢复AVAssetExportSession。
var exportSession = AVAssetExportSession.init(asset: composition, presetName: AVAssetExportPresetHighestQuality)
exportSession?.videoComposition = videoComposition
exportSession?.outputFileType = AVFileType.mov
exportSession?.outputURL = URL.init(fileURLWithPath: videoPath)
exportSession?.videoComposition = videoComposition
var exportProgress: Float = 0
let queue = DispatchQueue(label: "Export Progress Queue")
queue.async(execute: {() -> Void in
while exportSession != nil {
exportProgress = (exportSession?.progress)!
print("current progress == \(exportProgress)")
}
sleep(1)
}
})
exportSession?.exportAsynchronously(completionHandler: {
if exportSession?.status == AVAssetExportSessionStatus.failed {
print("Failed \(exportSession?.error?.localizedDescription)")
exportSession = nil
} else if exportSession?.status == AVAssetExportSessionStatus.completed {
exportSession = nil
VideoSave.saveVideoToPhotoLibrary(URL.init(fileURLWithPath: videoPath), error: nil)
}
})
假设导出进度完成50%的视频。因此,我将其导出过程暂停了50%,然后再次恢复。它应该从之前暂停的位置的50%恢复。