导出相册视频-> 本地沙盒

1, exportSession

let option = PHVideoRequestOptions()
                option.isNetworkAccessAllowed = true
                option.deliveryMode = .highQualityFormat
                PHCachingImageManager.default().requestExportSession(forVideo: asset, options: option, exportPreset: AVAssetExportPresetHighestQuality) { (exportSession, info) in
                    guard let exportSession = exportSession else {
                        single(.error(KimPhotoHelperError.sourceNotFound))
                        return
                    }
                    exportSession.outputURL = videoPath
                    exportSession.outputFileType = .mp4
                    exportSession.exportAsynchronously {
                        switch exportSession.status {
                        case .completed:
                            single(.success((videoPath.relativePath, size)))
                        case .failed:
                            print(exportSession.error)
                            single(.error(KimPhotoHelperError.sourceNotFound))
                        default:
                            break
                        }
                    }
                }

2,  PHAssetResourceManager

let resourceManager = PHAssetResourceManager.default()
                let option = PHAssetResourceRequestOptions()
                option.isNetworkAccessAllowed = true
                resourceManager.writeData(for: assetRescource, toFile: videoPath, options: option) { (error) in
                    guard let error = error else {
                        //single(.error(e))
                        exportSession(asset)
                        return
                    }
                    single(.success((videoPath.relativePath, size)))
                }

猜你喜欢

转载自www.cnblogs.com/daxueshan/p/12808761.html