瀏覽代碼

1, 推荐的开始和结束时间 ,卡点时间 都使用BASE_FILTER_TIMESCALE

jsonwang 3 年之前
父節點
當前提交
cdf0e8963a
共有 1 個文件被更改,包括 26 次插入19 次删除
  1. 26 19
      BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

+ 26 - 19
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -120,7 +120,7 @@ class PQStuckPointEditerController: PQBaseViewController {
                 self?.projectModel.sData?.getBGMSession()?.sectionTimeline?.audioTrack?.audioTrackMaterials.first?.timelineOut = Float64(endTime)
                 BFLog(message: "调整后总时长: \(endTime - startTime) startTime:\(startTime) endTime:\(endTime)")
                 // 初始化音频的开始和结束时间
-                self?.playeTimeRange = CMTimeRange(start: CMTime(value: CMTimeValue(Int64(startTime * 600)), timescale: 600), end: CMTime(value: CMTimeValue(Int64(endTime * 600)), timescale: 600))
+                self?.playeTimeRange = CMTimeRange(start: CMTimeMakeWithSeconds(Float64(startTime), preferredTimescale: BASE_FILTER_TIMESCALE), end: CMTimeMakeWithSeconds(Float64(endTime), preferredTimescale: BASE_FILTER_TIMESCALE))
 
                 DispatchQueue.global().async { // 并行、异步
                     let beginTime: TimeInterval = Date().timeIntervalSince1970
@@ -397,6 +397,8 @@ class PQStuckPointEditerController: PQBaseViewController {
                 let audioPath = self.stuckPointMusicData?.localPath ?? ""
                 BFLog(message: "初始化音频播放器的音频地址为:\(audioPath)")
                 self.playerView.stop()
+        // 这里的测试这个音乐播放有问题
+//        self.playerView.updateAsset(URL(fileURLWithPath: "63930549652d74e477141e3b79c8d29a9ef8af81625053214516.mp3", relativeTo:Bundle.main.resourceURL!), videoComposition: nil, audioMixModel: nil)
                 self.playerView.updateAsset(URL(fileURLWithPath: documensDirectory + audioPath), videoComposition: nil, audioMixModel: nil)
 
                 let end2: TimeInterval = Date().timeIntervalSince1970
@@ -533,9 +535,9 @@ extension PQStuckPointEditerController {
 
                 var stuckPointsTemp = Array<Float>.init()
                 for (index, dunshu) in stuckPointMusicData!.rhythmSdata[0].pointTimes.enumerated() {
-                    BFLog(message: "所有卡点数:\(Float64(dunshu) / 1_000_000.0)")
-                    if Float64(dunshu) / 1_000_000.0 > CMTimeGetSeconds(playeTimeRange.start), Float64(dunshu) / 1_000_000.0 < CMTimeGetSeconds(playeTimeRange.end) {
-                        stuckPointsTemp.append(Float(dunshu) / 1_000_000.0)
+                    BFLog(message: "原所有卡点数:\(index) \(Float(dunshu) / Float(BASE_FILTER_TIMESCALE))")
+                    if Float64(dunshu) / Float64(BASE_FILTER_TIMESCALE) > CMTimeGetSeconds(playeTimeRange.start), Float64(dunshu) / Float64(BASE_FILTER_TIMESCALE) < CMTimeGetSeconds(playeTimeRange.end) {
+                        stuckPointsTemp.append(Float(dunshu) / Float(BASE_FILTER_TIMESCALE))
                     }
                 }
 
@@ -548,7 +550,7 @@ extension PQStuckPointEditerController {
                 BFLog(message: "stuckPointMusicData?.speed is \(String(describing: stuckPointMusicData?.speed))")
                 for (index, point) in stuckPointsTemp.enumerated() {
                     if stuckPointMusicData?.speed == 1 {
-                        stuckPoints.append(point)
+                        stuckPoints.append(Float(point))
                     } else if stuckPointMusicData?.speed == 2 {
                         if index % 2 == 0 {
                             stuckPoints.append(point)
@@ -562,7 +564,7 @@ extension PQStuckPointEditerController {
                 }
 
                 for point in stuckPoints {
-                    BFLog(message: "有 start end 计算后的卡点数\(point)")
+                    BFLog(message: "有 start end 计算后的卡点数\(point)")
                 }
                 if stuckPoints.first != nil {
                     stuckPoints.removeFirst()
@@ -570,9 +572,14 @@ extension PQStuckPointEditerController {
                 if stuckPoints.last != nil {
                     stuckPoints.removeLast()
                 }
+                //开始时间是服务器返回, 结果时间根据策略计算的
                 stuckPoints.insert(Float(CMTimeGetSeconds(playeTimeRange.start)), at: 0)
-                stuckPoints.insert(Float(CMTimeGetSeconds(playeTimeRange.end)), at: stuckPoints.count)
+                stuckPoints.insert((Float(CMTimeGetSeconds(playeTimeRange.end))), at: stuckPoints.count)
 
+                for point in stuckPoints {
+                    BFLog(message: "有 start end 计算后的卡点数\(point)")
+                }
+                
                 BFLog(message: "stuckPoints count is \(stuckPoints.count)")
                 // 当用户上传视觉素材个数大于等于音乐选择区域节拍分割个数时,无需进行视频分割,只显示卡点数-1 个素材
                 if section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials().count >= stuckPointMusicData!.rhythmSdata[0].pointTimes.count {
@@ -582,9 +589,8 @@ extension PQStuckPointEditerController {
                             break
                         }
                         BFLog(message: "创建 filter start :\(sticker.timelineIn) end :\(sticker.timelineOut) type is \(sticker.type) \(sticker.locationPath)")
-
-                        sticker.timelineIn = Float64(stuckPoints[index])
-                        sticker.timelineOut = Float64(stuckPoints[index + 1])
+                        sticker.timelineIn = Float64("\(stuckPoints[index])") ?? 0.0
+                        sticker.timelineOut = Float64("\(stuckPoints[index + 1])") ?? 0.0
                         BFLog(message: "卡点 间隔 \(sticker.timelineIn - sticker.timelineOut)")
                         sticker.generateDefaultValues()
                         stickers.append(sticker)
@@ -603,8 +609,8 @@ extension PQStuckPointEditerController {
                             let deepCopySticker = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: stickerjson!)
                             if deepCopySticker!.type == StickerType.IMAGE.rawValue {
                                 if index + 1 < stuckPoints.count {
-                                    deepCopySticker!.timelineIn = Float64(stuckPoints[index])
-                                    deepCopySticker!.timelineOut = Float64(stuckPoints[index + 1])
+                                    deepCopySticker!.timelineIn = Float64("\(stuckPoints[index])") ?? 0.0
+                                    deepCopySticker!.timelineOut = Float64("\(stuckPoints[index + 1])") ?? 0.0
                                     if deepCopySticker != nil {
                                         deepCopySticker?.generateDefaultValues()
                                         stickers.append(deepCopySticker!)
@@ -616,19 +622,19 @@ extension PQStuckPointEditerController {
                         // 第二种情况:有视频要进行分割
                         let clipFilters = clipVideoMerage(section: section, stuckPoints: stuckPoints)
                         for (index, point) in stuckPoints.enumerated() {
-                            BFLog(message: "aaaaaindexindeindexxindexindexindex \(index)")
+                            BFLog(message: "aaaaaindexindeindexxindexindexindex \(index) \(point)")
                             if index + 1 < stuckPoints.count, index < clipFilters.count {
-                                BFLog(message: "bbbbbindexindeindexxindexindexindex \(index)")
+                                BFLog(message: "bbbbbindexindeindexxindexindexindex \(index) \(point)")
                                 let sticker: PQEditVisionTrackMaterialsModel = clipFilters[index]
-                                sticker.timelineIn = Float64(stuckPoints[index])
+                                sticker.timelineIn = Float64("\(stuckPoints[index])") ?? 0.0
                                 // TODO 不是最好方案
-                                sticker.timelineOut = Float64(stuckPoints[index + 1]) + 1
+                                sticker.timelineOut = Float64("\(stuckPoints[index + 1] )") ?? 0.0
                                 // 卡点的时间 >  in out 值 这里就会出现鬼畜效果
                                 let timelineInterval = sticker.timelineOut - sticker.timelineIn
                                 let inOutInterval = sticker.out - sticker.model_in
                                 if timelineInterval > inOutInterval {
                                     BFLog(message: "实际要显示卡点时长\(timelineInterval) 素材裁剪时长:\(inOutInterval)")
-                                    sticker.out = sticker.model_in + timelineInterval + 0.01
+                                    sticker.out = sticker.model_in + timelineInterval
                                     
                                     //下面只是 LOG 方便查问题
                                     let stickerInOut = sticker.out - sticker.model_in
@@ -642,7 +648,7 @@ extension PQStuckPointEditerController {
                                 // out > 素材的总时长in out 进行前移操作
                                 let offsetAssetDuration = sticker.out - sticker.duration
                                 if offsetAssetDuration > 0 {
-                                    sticker.model_in = sticker.model_in - offsetAssetDuration - 0.01
+                                    sticker.model_in = sticker.model_in - offsetAssetDuration
                                     sticker.out = sticker.out - offsetAssetDuration
                                 }
 
@@ -838,7 +844,8 @@ extension PQStuckPointEditerController {
         if !isSynchroMusicInfoSuccess  || !isStuckPointDataSuccess || !isExportVideosSuccess {
             return
         }
-        playeTimeRange = CMTimeRange(start: CMTime(value: CMTimeValue(Int64((stuckPointMusicData?.startTime ?? 0) * 600)), timescale: 600), end: CMTime(value: CMTimeValue(Int64((stuckPointMusicData?.endTime ?? 0) * 600)), timescale: 600))
+ 
+        playeTimeRange = CMTimeRange(start:  CMTimeMakeWithSeconds(stuckPointMusicData?.startTime ?? 0, preferredTimescale: BASE_FILTER_TIMESCALE), end: CMTimeMakeWithSeconds(stuckPointMusicData?.endTime ?? 0, preferredTimescale: BASE_FILTER_TIMESCALE))
         createPorjectData()
         settingPlayerView()