修复完成转换视频后会同时导出多个结果的bug

This commit is contained in:
bluesea 2024-03-11 17:02:48 +08:00
parent 2856b13cbe
commit f9cd80af4b
3 changed files with 12 additions and 28 deletions

View File

@ -588,30 +588,14 @@ extension VRVideoTransformController {
let outputVideoURL = URL.documentsDirectory.appending(path:"convertor_one.mov")
let videoOriginalAsset:AVAsset? = AVAsset(url: sourceVideoURL!)
Task {
try await spatialVideoConver.convertVideo(asset: videoOriginalAsset!, outputFile: outputVideoURL ,type: self.selected3DFormat) { [self] progress in
try await spatialVideoConver.convertVideo(asset: videoOriginalAsset!, outputFile: outputVideoURL ,type: self.selected3DFormat) { [self] (progress,state) in
print(progress)
// DispatchQueue.main.async { [weak self] in
if(progress > 0.99){
DispatchQueue.main.asyncAfter(deadline: .now() + 20) {
//
self.exportVideo(url: outputVideoURL, outputURL: outputURL, width: width, height: height,codecType:codecType, dataRate: dataRate, horizontalDisparity: horizontalDisparity, horizontalFieldOfView: horizontalFieldOfView) { exportedAsset in
DispatchQueue.main.async {
PHPhotoLibrary.shared().performChanges {
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: outputURL)
} completionHandler: { isSuccess, error in
if isSuccess {
SVProgressHUD.showSuccess(withStatus: "成功导出视频")
} else {
SVProgressHUD.showSuccess(withStatus: "导出视频失败")
}
}
}
}
if(state){
print("zzh the progress \(progress)")
//
self.exportVideo(url: outputVideoURL, outputURL: outputURL, width: width, height: height,codecType:codecType, dataRate: dataRate, horizontalDisparity: horizontalDisparity, horizontalFieldOfView: horizontalFieldOfView) { exportedAsset in
}
}
// }
}
}
}
}
@ -709,7 +693,7 @@ extension VRVideoTransformController {
}
assetExportSession.videoComposition = AVMutableVideoComposition(propertiesOf: composition)
assetExportSession.outputFileType = AVFileType.mp4
assetExportSession.outputFileType = AVFileType.mov
assetExportSession.outputURL = outputURL
assetExportSession.exportAsynchronously { [self] in
@ -737,7 +721,7 @@ extension VRVideoTransformController {
case .cancelled:
print("Export cancelled")
DispatchQueue.main.async {
SVProgressHUD.showInfo(withStatus: "视频导出失败")
SVProgressHUD.showInfo(withStatus: "视频导出失败 cancelled")
}
completion(nil)
default:

View File

@ -22,7 +22,7 @@ class SpatialVideoConvertor {
func convertVideo( asset : AVAsset, outputFile: URL,type:Video3DFormat, progress: ((Float)->())? = nil ) async throws {
func convertVideo( asset : AVAsset, outputFile: URL,type:Video3DFormat, progress: ((Float,Bool)->())? = nil ) async throws {
do {
try FileManager.default.removeItem(atPath: outputFile.path)
print("视频文件删除成功")
@ -168,7 +168,7 @@ class SpatialVideoConvertor {
print( "Added frame at \(time)")
// callback with progress
progress?( Float(time.value)/Float(duration.value))
progress?( Float(time.value)/Float(duration.value),false)
// This sleep is needed to stop memory blooming - keeps around 280Mb rather than spiraling up to 8+Gig!
try await Task.sleep(nanoseconds: 3_000_000)
@ -184,7 +184,7 @@ class SpatialVideoConvertor {
print( "Finished")
_ = try await vw!.finish()
progress?( Float(1.0),true)
}

View File

@ -102,7 +102,7 @@ class SpatialVideoWriter {
print("可以保存")
completion(true, nil)
self.saveVideoToLibrary(videoURL: outputVideoURL, completion: completion)
// self.saveVideoToLibrary(videoURL: outputVideoURL, completion: completion)
}
} catch {
print("生成失败")