From e62f93f9a7fa8343956de041eb031961a3840e94 Mon Sep 17 00:00:00 2001 From: bluesea <307723040@qq.com> Date: Thu, 14 Mar 2024 10:08:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dapp=E5=86=85=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=8B=8D=E6=91=84=E5=AE=8C=E6=AF=95=E5=90=8E=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E8=A7=86=E9=A2=91=E8=87=B3=E7=9B=B8=E5=86=8C=E7=9A=84?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CCSpatialShootController.swift | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/SwiftProject/SwiftProject/Project/Controller/RecordingVideo/CCSpatialShootController.swift b/SwiftProject/SwiftProject/Project/Controller/RecordingVideo/CCSpatialShootController.swift index 9b1befa..4d31ad3 100644 --- a/SwiftProject/SwiftProject/Project/Controller/RecordingVideo/CCSpatialShootController.swift +++ b/SwiftProject/SwiftProject/Project/Controller/RecordingVideo/CCSpatialShootController.swift @@ -370,6 +370,11 @@ class CCSpatialShootController: BaseController { } do { + print("builtInWideAngleCamera:\(backCamera.videoZoomFactor)") +// try backCamera.lockForConfiguration() +// backCamera.videoZoomFactor=3.0 +// backCamera.unlockForConfiguration() + wideAngleCameraDeviceInput = try AVCaptureDeviceInput(device: backCamera) guard let wideAngleCameraDeviceInput = wideAngleCameraDeviceInput, @@ -390,8 +395,13 @@ class CCSpatialShootController: BaseController { } do { + print("builtInUltraWideCamera:\(frontCamera.videoZoomFactor)") +// try frontCamera.lockForConfiguration() +// frontCamera.videoZoomFactor = 8.0//变焦 +// frontCamera.unlockForConfiguration() + // 设置焦距 +// frontCamera.focusMode = .autoFocus ultraWideCameraDeviceInput = try AVCaptureDeviceInput(device: frontCamera) - guard let ultraWideCameraDeviceInput = ultraWideCameraDeviceInput, session.canAddInput(ultraWideCameraDeviceInput) else { print("Could not add front camera input") @@ -936,12 +946,13 @@ extension CCSpatialShootController: AVCaptureFileOutputRecordingDelegate { if(rightEyeVideoURL != nil && leftEyeVideoURL != nil){ let spatialVideoWriter = SpatialVideoWriter() Task { - spatialVideoWriter.writeSpatialVideo(leftEyeVideoURL: leftEyeVideoURL!, rightEyeVideoURL: rightEyeVideoURL!, outputVideoURL: outputVideoURL!) { success, error in + spatialVideoWriter.writeSpatialVideo(leftEyeVideoURL: leftEyeVideoURL!, rightEyeVideoURL: rightEyeVideoURL!, outputVideoURL: outputVideoURL!) {[self] success, error in DispatchQueue.main.async { SVProgressHUD.dismiss() } if success { print("空间视频生成成功") + saveVideoToLibrary(videoURL:outputVideoURL!) DispatchQueue.main.async { SVProgressHUD.showSuccess(withStatus: "空间视频成功保存到相册") } @@ -957,6 +968,19 @@ extension CCSpatialShootController: AVCaptureFileOutputRecordingDelegate { } } + private func saveVideoToLibrary(videoURL: URL) { + PHPhotoLibrary.shared().performChanges({ + PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: videoURL) + }) { success, error in + if success { + print("保存成功") + } else if let error = error { + print("保存失败") + } + } + } + + //MARK: 空间图片合成 private func firstFrame(from videoURL: URL) -> UIImage? { let asset = AVURLAsset(url: videoURL)