From f9cd80af4b3a25d7a594a8c190554166fa686260 Mon Sep 17 00:00:00 2001 From: bluesea <307723040@qq.com> Date: Mon, 11 Mar 2024 17:02:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=8C=E6=88=90=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E8=A7=86=E9=A2=91=E5=90=8E=E4=BC=9A=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=A4=9A=E4=B8=AA=E7=BB=93=E6=9E=9C=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VRVideoTransformController.swift | 32 +++++-------------- .../Project/Util/SpatialVideoConvertor.swift | 6 ++-- .../Project/Util/SpatialVideoWriter.swift | 2 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/SwiftProject/SwiftProject/Project/Controller/RecordingVideo/VRVideoTransformController.swift b/SwiftProject/SwiftProject/Project/Controller/RecordingVideo/VRVideoTransformController.swift index eb1a4ee..d1d292b 100644 --- a/SwiftProject/SwiftProject/Project/Controller/RecordingVideo/VRVideoTransformController.swift +++ b/SwiftProject/SwiftProject/Project/Controller/RecordingVideo/VRVideoTransformController.swift @@ -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: diff --git a/SwiftProject/SwiftProject/Project/Util/SpatialVideoConvertor.swift b/SwiftProject/SwiftProject/Project/Util/SpatialVideoConvertor.swift index c5d27bc..0cf650d 100644 --- a/SwiftProject/SwiftProject/Project/Util/SpatialVideoConvertor.swift +++ b/SwiftProject/SwiftProject/Project/Util/SpatialVideoConvertor.swift @@ -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) } diff --git a/SwiftProject/SwiftProject/Project/Util/SpatialVideoWriter.swift b/SwiftProject/SwiftProject/Project/Util/SpatialVideoWriter.swift index 17a6abf..23cab76 100644 --- a/SwiftProject/SwiftProject/Project/Util/SpatialVideoWriter.swift +++ b/SwiftProject/SwiftProject/Project/Util/SpatialVideoWriter.swift @@ -102,7 +102,7 @@ class SpatialVideoWriter { print("可以保存") completion(true, nil) - self.saveVideoToLibrary(videoURL: outputVideoURL, completion: completion) +// self.saveVideoToLibrary(videoURL: outputVideoURL, completion: completion) } } catch { print("生成失败")