瀏覽代碼

1,修改时间对比精度 2, 出错弹出提示 3, 添加假的进度。

jsonwang 3 年之前
父節點
當前提交
37857e14a8
共有 1 個文件被更改,包括 14 次插入6 次删除
  1. 14 6
      BFFramework/Classes/Stuckpoint/Controller/PQStuckPointPublicController.swift

+ 14 - 6
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointPublicController.swift

@@ -636,8 +636,8 @@ extension PQStuckPointPublicController {
 
         let originaDuration = CMTimeGetSeconds(clipAudioRange.duration)
         BFLog(message: "处理主音频 原始时长startTime = \(originaDuration) 要显示时长totalDuration = \(mTotalDuration)")
-
-        if Float64(mTotalDuration) <= originaDuration {
+        //originaDuration =  37.616768 mTotalDuration = 37.616776 TODO 都用 INT 微秒级
+        if  Float64(String(format: "%.3f",mTotalDuration)) ?? 0.0 <=  Float64(String(format: "%.3f",originaDuration)) ?? 0.0 {
             BFLog(message: "不用拼接音频文件 \(originAsset.url) 时长is \(CMTimeGetSeconds(originAsset.duration))")
             completeHander(originAsset.url)
             return
@@ -671,7 +671,8 @@ extension PQStuckPointPublicController {
                 let tracks = audioAsset.tracks(withMediaType: .audio)
                 if tracks.count == 0 {
                     BFLog(message: "音频数据无效不进行合并,所有任务结束要确保输入的数据都正常! \(originAsset.url)")
-                    break
+                    completeHander(URL(string: ""))
+                    return
                 }
                 let assetTrack: AVAssetTrack = tracks[0]
 
@@ -699,6 +700,8 @@ extension PQStuckPointPublicController {
             let tracks = audioAsset.tracks(withMediaType: .audio)
             if tracks.count == 0 {
                 BFLog(message: "音频数据无效不进行合并,所有任务结束要确保输入的数据都正常! \(originAsset.url)")
+                completeHander(URL(string: ""))
+                return
             }
             let assetTrack: AVAssetTrack = tracks[0]
 
@@ -709,7 +712,7 @@ extension PQStuckPointPublicController {
                 try compositionAudioTrack.insertTimeRange(timeRange, of: assetTrack, at: totalDuration)
 
             } catch {
-                BFLog(message: "error is \(error)")
+                BFLog(message: "合并音频 error is \(error)")
                 completeHander(URL(string: ""))
                 return
             }
@@ -746,13 +749,18 @@ extension PQStuckPointPublicController {
     }
 
     func appendAudio() {
+        //更新一下假进度
+        updatePublicCurrentProgress(useProgress: 0.01)
         let inputAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + (audioMixModel?.localPath ?? "")), options: nil)
+        let startMergeTime = CFAbsoluteTimeGetCurrent()
         mergeAudios(originAsset: inputAsset, mTotalDuration: finallyUserAudioTime, clipAudioRange: clipAudioRange, mStartTime: CMTime(value: CMTimeValue((mStickers?.first?.timelineIn ?? 0.0) * Float64(playerTimescaleInt)), timescale: playerTimescaleInt)) { [weak self] completURL in
 
             if completURL != nil {
                 let asset = AVURLAsset(url: completURL!, options: nil)
-                FilterLog(message: "拼接后音频时长\(asset.duration.seconds)  url is \(String(describing: completURL))")
+                BFLog(message: "拼接后音频时长\(asset.duration.seconds)  url is \(String(describing: completURL)) 用时\(CFAbsoluteTimeGetCurrent() - startMergeTime)")
                 self?.beginExport(inputAsset: asset)
+            }else{
+                cShowHUB(superView: self?.view, msg: "合成失败请重试。")
             }
         }
     }
@@ -772,7 +780,7 @@ extension PQStuckPointPublicController {
         let outPutMP4URL = URL(fileURLWithPath: outPutMP4Path)
         BFLog(message: "导出视频地址 \(outPutMP4URL)")
 
-        exporter = PQCompositionExporter(asset: inputAsset, videoComposition: nil, audioMix: audioMix, filters: nil, stickers: mStickers, animationTool: nil, exportURL: outPutMP4URL)
+        exporter = PQCompositionExporter(asset: inputAsset, videoComposition: nil, audioMix: nil, filters: nil, stickers: mStickers, animationTool: nil, exportURL: outPutMP4URL)
 
         var orgeBitRate = (editProjectModel?.sData?.videoMetaData?.videoWidth ?? 0) * (editProjectModel?.sData?.videoMetaData?.videoHeight ?? 0) * 3