Bläddra i källkod

1,图片时长计算,2,创建 filter 逻辑修改

jsonwang 3 år sedan
förälder
incheckning
bbde7f4554
1 ändrade filer med 65 tillägg och 106 borttagningar
  1. 65 106
      BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

+ 65 - 106
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -27,7 +27,7 @@ class PQStuckPointEditerController: PQBaseViewController {
     var isSynchroMusicInfoSuccess: Bool = false
     /// 当前所有的filter
     var filters: Array = Array<ImageProcessingOperation>.init()
-    // 选中所有素材的的总时长 其中图片时长为1.5
+    // 选中所有素材的的总时长 已经不包括图片的时长
     var selectedTotalDuration: Float64 = 0
     // 选择的总数
     var selectedDataCount: Int = 0
@@ -155,7 +155,7 @@ class PQStuckPointEditerController: PQBaseViewController {
                 // 初始化音频的开始和结束时间
                 self?.playeTimeRange = CMTimeRange(start: CMTimeMakeWithSeconds(Float64(startTime), preferredTimescale: BASE_FILTER_TIMESCALE), end: CMTimeMakeWithSeconds(Float64(endTime), preferredTimescale: BASE_FILTER_TIMESCALE))
 
-                DispatchQueue.global().async { // 并行、异步
+//                DispatchQueue.global().async { // 并行、异步
                     let beginTime: TimeInterval = Date().timeIntervalSince1970
                     self?.mStickers = self?.createStickers(sections: self?.projectModel.sData?.sections ?? List(), inputSize: CGSize(width: CGFloat(self?.projectModel.sData?.videoMetaData?.videoWidth ?? 0), height: CGFloat(self?.projectModel.sData?.videoMetaData?.videoHeight ?? 0)))
 
@@ -165,13 +165,9 @@ class PQStuckPointEditerController: PQBaseViewController {
                         BFLog(message: "endTime is endTimeendTime \(endTime = beginTime)")
                         self?.playerView.play(pauseFirstFrame: false, playeTimeRange: self!.playeTimeRange)
                     }
-                }
-            }
-            // 埋点上报
-            if type == 1 || type == 2 {
-                // 点击上报:拖动拖拽条(左/右部分)r
-                PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: type == 1 ? .ot_click_dragFront : .ot_click_dragBehind, pageSource: .sp_stuck_previewSyncedUp, extParams: ["targetTime": type == 1 ? startTime * 1000 : endTime * 1000], remindmsg: "点击上报:拖动拖拽条(左/右部分)")
+//                }
             }
+   
         }
         return stuckPointCuttingView
     }()
@@ -329,6 +325,7 @@ class PQStuckPointEditerController: PQBaseViewController {
                 self?.customSpeedSettingView.isHidden = false
                 self?.customSpeedSettingView.isJumpSpeedModel = speedSettingView.viewType == 2
             }
+            self?.settingPlayerView()
         }
         return speedSettingView
 
@@ -343,7 +340,7 @@ class PQStuckPointEditerController: PQBaseViewController {
             self?.maxSpeed = maxSpeed
             self?.minSpeed = minSpeed
             BFLog(message: "自定义速度maxSpeed is\(maxSpeed) minSpeed \(minSpeed) \(isJumpSpeedModel)")
-        
+            self?.settingPlayerView()
         }
         return customSpeedSettingView
 
@@ -465,6 +462,13 @@ class PQStuckPointEditerController: PQBaseViewController {
 
     // 三种模式修改
     @objc func editModelClick(sender: UIButton) {
+        
+        //1,根据条件判断哪些功能不可用直接出提示
+//        if(selectedDataCount == selectedImageDataCount && (sender == speedStuckBtn || sender == onlyMusicBtn )){
+//            BFLog(message: "全是图片 \(selectedDataCount) \(selectedImageDataCount)")
+//            cShowHUB(superView: self.view, msg: "1111")
+//            return
+//        }
         if sender.isSelected {
             BFLog(message: "已经是选中状态")
             return
@@ -940,71 +944,12 @@ extension PQStuckPointEditerController {
         
         // 推荐卡点数
         dealParameter(model: model)
-        let stuckPoints: Array = finallyStuckPoints
-        
         // 保存滤镜对象数据
         var stickers: Array = Array<PQEditVisionTrackMaterialsModel>.init()
         if model == .createStickersModelPoint { //跳跃卡点
             for section in sections {
                 if section.sectionType == "normal" {
-                    // 推荐卡点数
-                    var stuckPoints: Array = Array<Float>.init()
-
-                    var stuckPointsTemp = Array<Float>.init()
-                    for (index, dunshu) in stuckPointMusicData!.rhythmSdata[0].pointTimes.enumerated() {
-                        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))
-                        }
-                    }
-
-                    /* 快慢速模式下取卡点 1 3 5
-                     - 快节奏为选中区域的所有点位,即0,1,2,3,4 5 6 7 8 9 10 ……
-                     - 适中为每两个点位取一个,即0,3,6,9 12
-                     - 慢节奏为每三个点位取一个,即0 5 10 15
-                     慢节奏要做特殊处理
                  
-                     */
-                    // 跳跃卡点模式下根据不同速度 取卡点 1,2,3
-                    /*
-                     - 快节奏为选中区域的所有点位,即0,1,2,3,4……
-                     - 适中为每两个点位取一个,即0,2,4,6……
-                     - 慢节奏为每三个点位取一个,即0,3,6,9……
-                     */
-                    BFLog(message: "stuckPointMusicData?.speed is \(String(describing: stuckPointMusicData?.speed))")
-                    for (index, point) in stuckPointsTemp.enumerated() {
-                        if stuckPointMusicData?.speed == 1 {
-                            stuckPoints.append(Float(point))
-                        } else if stuckPointMusicData?.speed == 2 {
-                            if index % 2 == 0 {
-                                stuckPoints.append(point)
-                            }
-
-                        } else if stuckPointMusicData?.speed == 3 {
-                            if index % 3 == 0 {
-                                stuckPoints.append(point)
-                            }
-                        }
-                    }
-
-                    for point in stuckPoints {
-                        BFLog(message: "没有 start end 计算后的卡点数\(point)")
-                    }
-                    if stuckPoints.first != nil {
-                        stuckPoints.removeFirst()
-                    }
-                    if stuckPoints.last != nil {
-                        stuckPoints.removeLast()
-                    }
-                    // 开始时间是服务器返回, 结果时间根据策略计算的
-                    stuckPoints.insert(Float(CMTimeGetSeconds(playeTimeRange.start)), at: 0)
-                    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 {
                         for (index, sticker) in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials().enumerated() {
@@ -1013,8 +958,8 @@ extension PQStuckPointEditerController {
                                 break
                             }
                             BFLog(message: "创建 filter start :\(sticker.timelineIn) end :\(sticker.timelineOut) type is \(sticker.type) \(sticker.locationPath)")
-                            sticker.timelineIn = Float64("\(stuckPoints[index])") ?? 0.0
-                            sticker.timelineOut = Float64("\(stuckPoints[index + 1])") ?? 0.0
+                            sticker.timelineIn = Float64("\(finallyStuckPoints[index])") ?? 0.0
+                            sticker.timelineOut = Float64("\(finallyStuckPoints[index + 1])") ?? 0.0
                             BFLog(message: "卡点 间隔 \(sticker.timelineIn - sticker.timelineOut)")
                             sticker.generateDefaultValues()
                             stickers.append(sticker)
@@ -1025,16 +970,17 @@ extension PQStuckPointEditerController {
 
                         // 第一种情况:全是图片,图片回环播放
                         if section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "video").count == 0, section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "image").count > 0 {
-                            for (index, point) in stuckPoints.enumerated() {
+                            for (index, point) in finallyStuckPoints.enumerated() {
                                 let sticker: PQEditVisionTrackMaterialsModel = section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials()[index % section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials().count]
                                 BFLog(message: "stickerlocationPath sticker : \(sticker.locationPath)")
                                 let stickerjson = sticker.toJSONString(prettyPrint: false)
 
                                 let deepCopySticker = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: stickerjson!)
                                 if deepCopySticker!.type == StickerType.IMAGE.rawValue {
-                                    if index + 1 < stuckPoints.count {
-                                        deepCopySticker!.timelineIn = Float64("\(stuckPoints[index])") ?? 0.0
-                                        deepCopySticker!.timelineOut = Float64("\(stuckPoints[index + 1])") ?? 0.0
+                                    if index + 1 < finallyStuckPoints.count {
+                                        deepCopySticker!.timelineIn = Float64("\(finallyStuckPoints[index])") ?? 0.0
+                                        
+                                        deepCopySticker!.timelineOut = Float64("\(finallyStuckPoints[index + 1])") ?? 0.0
                                         if deepCopySticker != nil {
                                             deepCopySticker?.generateDefaultValues()
                                             stickers.append(deepCopySticker!)
@@ -1044,15 +990,15 @@ extension PQStuckPointEditerController {
                             }
                         } else {
                             // 第二种情况:有视频要进行分割
-                            let clipFilters = clipVideoMerage(section: section, stuckPoints: stuckPoints)
-                            for (index, point) in stuckPoints.enumerated() {
+                            let clipFilters = clipVideoMerage(section: section, stuckPoints: finallyStuckPoints)
+                            for (index, point) in finallyStuckPoints.enumerated() {
                                 BFLog(message: "aaaaaindexindeindexxindexindexindex \(index) \(point)")
-                                if index + 1 < stuckPoints.count, index < clipFilters.count {
+                                if index + 1 < finallyStuckPoints.count, index < clipFilters.count {
                                     BFLog(message: "bbbbbindexindeindexxindexindexindex \(index) \(point)")
                                     let sticker: PQEditVisionTrackMaterialsModel = clipFilters[index]
-                                    sticker.timelineIn = Float64("\(stuckPoints[index])") ?? 0.0
+                                    sticker.timelineIn = Float64("\(finallyStuckPoints[index])") ?? 0.0
                                  
-                                    sticker.timelineOut = Float64("\(stuckPoints[index + 1])") ?? 0.0
+                                    sticker.timelineOut = Float64("\(finallyStuckPoints[index + 1])") ?? 0.0
                                     // 卡点的时间 >  in out 值 这里就会出现鬼畜效果
                                     let timelineInterval = sticker.timelineOut - sticker.timelineIn
                                     let inOutInterval = sticker.out - sticker.model_in
@@ -1088,7 +1034,7 @@ extension PQStuckPointEditerController {
             for section in sections {
                 if section.sectionType == "normal" {
               
-                    BFLog(message: "stuckPoints count is \(stuckPoints.count)")
+                    BFLog(message: "stuckPoints count is \(finallyStuckPoints.count)")
                   
                     //一共裁剪的段数
                     var totalClipNum:Int = 0
@@ -1103,18 +1049,18 @@ extension PQStuckPointEditerController {
                             var realUsedMusicDuration = 0.0
                             while realUsedMusicDuration <= CMTimeGetSeconds(asset.duration) {
                                 //快速段
-                                let LA = maxSpeed * (stuckPoints[i+1] - stuckPoints[i])
+                                let LA = maxSpeed * (finallyStuckPoints[i+1] - finallyStuckPoints[i])
                                 realUsedMusicDuration = realUsedMusicDuration + Float64(LA)
                                 if(realUsedMusicDuration > CMTimeGetSeconds(asset.duration)){ break}
                                 oneVideoClipNum = oneVideoClipNum + 1
                                 //慢速段
-                                let LB = minSpeed * (stuckPoints[i+2] - stuckPoints[i+1])
+                                let LB = minSpeed * (finallyStuckPoints[i+2] - finallyStuckPoints[i+1])
                                 realUsedMusicDuration = realUsedMusicDuration + Float64(LB)
                                 oneVideoClipNum = oneVideoClipNum + 1
                                 i = i + 1
                             }
                             BFLog(message: "单个视频\(sticker.locationPath)时长::\(CMTimeGetSeconds(asset.duration)) ,clipNum is:\(oneVideoClipNum)")
-                        
+                            var lastOutTime:Float64 = 0.0
                             for clipindex in 0 ... oneVideoClipNum - 1 {
                                 // deep copy sticker model 防止只有一个对象
                                 let stickerjson = sticker.toJSONString(prettyPrint: false)
@@ -1122,16 +1068,26 @@ extension PQStuckPointEditerController {
                                 // 设置循环模式和适配模式
                                 deepCopySticker?.generateDefaultValues()
                                 //当前分段的速度
-                                let tempSpeed = (totalClipNum + clipindex) % 2 == 0 ? maxSpeed : minSpeed
-                                if(totalClipNum + 1 + clipindex < stuckPoints.count){
+                                var tempSpeed = (totalClipNum + clipindex) % 2 == 0 ? maxSpeed : minSpeed
+//                                tempSpeed = 2
+                                if(totalClipNum + 1 + clipindex < finallyStuckPoints.count){
                                     deepCopySticker?.speedRate = tempSpeed
-                                    deepCopySticker?.model_in = Float64(tempSpeed) * Float64(stuckPoints[totalClipNum + clipindex] - (stuckPoints.first ?? 0.0))
-                                    deepCopySticker?.out = Float64(tempSpeed) * Float64(stuckPoints[totalClipNum + 1 + clipindex] - (stuckPoints.first ?? 0.0))
-                                    deepCopySticker?.timelineIn = Float64(stuckPoints[totalClipNum + clipindex])
-                                    deepCopySticker?.timelineOut = Float64(stuckPoints[totalClipNum + 1 + clipindex])
+                                    
+//                                    deepCopySticker?.model_in = Float64(tempSpeed) * Float64(finallyStuckPoints[totalClipNum + clipindex] - (finallyStuckPoints.first ?? 0.0))
+                                    deepCopySticker?.model_in = lastOutTime
+                                    
+                                    deepCopySticker?.out = lastOutTime + Float64(tempSpeed) * Float64(finallyStuckPoints[totalClipNum + 1 + clipindex] - finallyStuckPoints[totalClipNum + clipindex])
+                                    
+//                                    deepCopySticker?.out = lastOutTime +   Float64(finallyStuckPoints[totalClipNum + 1 + clipindex] - finallyStuckPoints[totalClipNum + clipindex])
+   
+                                    lastOutTime =  deepCopySticker?.out ?? 0
+                                    
+                                    deepCopySticker?.timelineIn =   Float64(finallyStuckPoints[totalClipNum + clipindex])
+                                    deepCopySticker?.timelineOut =    Float64(finallyStuckPoints[totalClipNum + 1 + clipindex])
+                                    
+                                    
                                 }
-                            
-                                BFLog(message: " crilp is in \(deepCopySticker?.model_in ?? 0) out \(deepCopySticker?.out ?? 0) timelineIN:\(deepCopySticker?.timelineIn ?? 0) timelineOUT:\(deepCopySticker?.timelineOut ?? 0) 总时长\(CMTimeGetSeconds(asset.duration)) speedRate:\(String(describing: deepCopySticker?.speedRate))")
+                                BFLog(message: " 创建 sticker crilp is in \(String(format: "%.6f", deepCopySticker?.model_in ?? 0)) out  \(String(format: "%.6f", deepCopySticker?.out ?? 0)) ,分段素材时长:\(String(format: "%.6f", (deepCopySticker?.out ?? 0) - (deepCopySticker?.model_in ?? 0))) ,分段显示时长:\(String(format: "%.6f", (deepCopySticker?.timelineOut ?? 0) - (deepCopySticker?.timelineIn ?? 0))), 总时长\(CMTimeGetSeconds(asset.duration)) timelineIN: \(String(format: "%.6f", deepCopySticker?.timelineIn ?? 0)) timelineOUT:\(String(format: "%.6f", deepCopySticker?.timelineOut ?? 0)) speedRate:\(deepCopySticker?.speedRate ?? 0.0)")
 
                                 if deepCopySticker != nil {
                                     stickers.append(deepCopySticker!)
@@ -1141,8 +1097,8 @@ extension PQStuckPointEditerController {
                             totalClipNum = totalClipNum + oneVideoClipNum - 1
                         } else if sticker.type == StickerType.IMAGE.rawValue {
                             sticker.generateDefaultValues()
-                            sticker.timelineIn = Float64(stuckPoints[totalClipNum])
-                            sticker.timelineOut = Float64(stuckPoints[totalClipNum + 1])
+                            sticker.timelineIn = Float64(finallyStuckPoints[totalClipNum])
+                            sticker.timelineOut = Float64(finallyStuckPoints[totalClipNum + 1])
                             stickers.append(sticker)
                         }
                     }
@@ -1154,7 +1110,7 @@ extension PQStuckPointEditerController {
             for section in sections {
                 if section.sectionType == "normal" {
 
-                    BFLog(message: "stuckPoints count is \(stuckPoints.count)")
+                    BFLog(message: "stuckPoints count is \(finallyStuckPoints.count)")
                     //已经计算过所有贴纸的累计时长,起点是推荐时长或用户划动后的时间
                     var totalStickerTimer:Float64 = CMTimeGetSeconds(playeTimeRange.start)
                     for sticker in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials() {
@@ -1267,6 +1223,10 @@ extension PQStuckPointEditerController {
         //保存丢卡点处理后的卡点信息推荐开始到最后倒数第二个
         let stuckPointsTemp = getUsedStuckPoint(seed: stuckPointMusicData?.speed ?? 0)
         
+        
+        if(selectedDataCount == selectedImageDataCount){
+        
+        }
         //最后真正要使用推荐结束时长
         var realUsedMusicDuration:Float = 0.0
         switch model {
@@ -1282,7 +1242,7 @@ extension PQStuckPointEditerController {
             while tempTime < Float(selectedTotalDuration) {
             
                 //回环从头取
-                if(i+2 > stuckPointsTemp.count){
+                if(i+2 >= stuckPointsTemp.count){
                     i = 0
                 }
                 //快速段
@@ -1562,12 +1522,16 @@ extension PQStuckPointEditerController {
         if !isSynchroMusicInfoSuccess || !isStuckPointDataSuccess || !isExportVideosSuccess {
             return
         }
-
         createPorjectData()
-      
-        BFLog(message: "界面编辑界面时参数 选择素材时长:\(selectedTotalDuration) 选择素材总数:\(selectedDataCount) 选择图片总数\(selectedImageDataCount)")
+  
+        //0 先计算所有图片的总时长 = 平均卡点时长  * 图片个数 * 档位
+        let avgPoint:Float = (Float(stuckPointMusicData!.rhythmSdata[0].pointTimes.last ?? 0) - Float(stuckPointMusicData!.rhythmSdata[0].pointTimes.first ?? 0))  / Float(stuckPointMusicData!.rhythmSdata[0].pointTimes.count) /  Float(BASE_FILTER_TIMESCALE) * Float(stuckPointMusicData?.speed ?? 2)
         
+        selectedTotalDuration = selectedTotalDuration + Float64(Float(selectedImageDataCount) * avgPoint)
+        
+        BFLog(message: "界面编辑界面时参数 选择素材时长:\(selectedTotalDuration) 选择素材总数:\(selectedDataCount) 选择图片总数\(selectedImageDataCount)")
         
+ 
         //1 生成默认参数值
         /*
          - 当素材总时长∈[0-6)s 时,提示推荐仅配乐模式 or 快慢速模式
@@ -1621,22 +1585,17 @@ extension PQStuckPointEditerController {
         /*
           文档规则 https://w42nne6hzg.feishu.cn/docs/doccnQZm1uCfkU4QtJb5fLxYk4d#
          */
-        //2,根据所选择所有素材时长判断哪些功能不可能用,及进入默认模式
+        //2,根据所选择所有素材时长进入默认模式
         //全是图片
         if(selectedDataCount == selectedImageDataCount){
             BFLog(message: "全是图片 \(selectedDataCount) \(selectedImageDataCount)")
-            speedStuckBtn.isEnabled = false
+ 
             //默认进入跳跃卡点模式
             editModelClick(sender: jumpPointBtn)
             speedSettingView.setSelectItem(index: lastJumpSpeedSelectIndex)
             
         }else{
-            
-            //1,根据素材输入确定可用模式及推荐模式
-            //1)0-6s时卡点不能使用, 纯图片时快慢速不可用
-            if(selectedTotalDuration > 0 && selectedTotalDuration < 6){
-                jumpPointBtn.isEnabled = false
-            }
+           
             //默认进入快慢速模式
             if(selectedTotalDuration > 0 && selectedTotalDuration <= 144){