Przeglądaj źródła

Merge branch 'master' of https://git.yishihui.com/iOS/BFFramework

wenweiwei 3 lat temu
rodzic
commit
08f37bc384

+ 35 - 6
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -57,7 +57,7 @@ class PQStuckPointEditerController: PQBaseViewController {
         let playerView = PQGPUImagePlayerView(frame: CGRect(x: 0, y: navHeadImageView?.frame.maxY ?? 0, width: playerHeight, height: playerHeight))
         playerView.backgroundColor = PQBFConfig.shared.styleBackGroundColor
         playerView.isShowLine = false
-        playerView.showGaussianBlur = true
+//        playerView.showGaussianBlur = true
         return playerView
     }()
 
@@ -472,7 +472,7 @@ extension PQStuckPointEditerController {
         // 所有视频总时长
         var videoTotalDuration: Float64 = 0.0
         for video in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "video") {
-            let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: video.locationPath), options: nil)
+            let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory +  video.locationPath), options: nil)
             videoTotalDuration = videoTotalDuration + Float64(CMTimeGetSeconds(asset.duration))
         }
         if videoTotalDuration == 0 {
@@ -481,7 +481,7 @@ extension PQStuckPointEditerController {
         }
         for sticker in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials() {
             if sticker.type == StickerType.VIDEO.rawValue {
-                let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: sticker.locationPath), options: nil)
+                let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory +  sticker.locationPath), options: nil)
                 // 要分割的段落
                 let clipNum = Int(max(round(Double(kongduan) * CMTimeGetSeconds(asset.duration) / videoTotalDuration), 1))
                 sticker.duration = CMTimeGetSeconds(asset.duration)
@@ -752,16 +752,36 @@ extension PQStuckPointEditerController {
                     PQPHAssetVideoParaseUtil.parasToAVAsset(phAsset: photo.asset!) { avAsset, fileSize, _, _ in
                         if avAsset is AVURLAsset {
                             // 创建目录
-
+                            
                             let fileName = (avAsset as! AVURLAsset).url.absoluteString
+            
                             BFLog(message: "video  fileName is\(fileName)")
                             let tempPhoto = self.selectedPhotoData?.first(where: { material in
                                 material.asset == photo.asset
                             })
                             
                             if(fileName.count ) > 0 {
-                                tempPhoto?.locationPath = fileName.replacingOccurrences(of: "file:///", with: "")
-                                BFLog(message: "导出视频相册地址为 \(fileName)")
+                                
+                                createDirectory(path: photoLibraryDirectory)
+                                let outFilePath = photoLibraryDirectory + fileName.md5 + ".mp4"
+                                // 文件存在先删除老文件
+                                if FileManager.default.fileExists(atPath: outFilePath) {
+                                    do {
+                                        try FileManager.default.removeItem(at: NSURL.fileURL(withPath: outFilePath))
+                                    } catch {
+                                        BFLog(message: "导出相册视频-error == \(error)")
+                                    }
+                                }
+                          
+                                do{
+                                           try FileManager.default.copyItem(atPath: fileName.replacingOccurrences(of: "file:///", with: ""), toPath: outFilePath)
+                                           print("Success to copy file.")
+                                }catch{
+                                           print("Failed to copy file.")
+                                }
+ 
+                                tempPhoto?.locationPath = outFilePath.replacingOccurrences(of: documensDirectory, with: "")
+                                BFLog(message: "导出视频相册地址为 \(String(describing: tempPhoto?.locationPath))")
                             }
  
                             DispatchQueue.main.async {
@@ -774,10 +794,19 @@ extension PQStuckPointEditerController {
                             
                         }
                     }
+             
   
                 }
             }
             
+            //只有图片
+            if(!isHaveVideo){
+                self.isExportVideosSuccess = true
+                BFLog(message: "所有相册视频导出成功")
+              
+                self.dealWithDataSuccess()
+            }
+            
         }
  
     }