如何在导出视频作品时暂停和恢复AVAssetExportSession

时间:2019-07-03 07:08:23

标签: ios swift cgaffinetransform avasset avassetexportsession

我正在尝试使用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%恢复。

0 个答案:

没有答案