Forráskód Böngészése

仅音乐逻辑调整

jsonwang 3 éve
szülő
commit
be968bfbc5

+ 95 - 5
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -1069,7 +1069,7 @@ extension PQStuckPointEditerController {
                                 deepCopySticker?.generateDefaultValues()
                                 //当前分段的速度
                                 var tempSpeed = (totalClipNum + clipindex) % 2 == 0 ? maxSpeed : minSpeed
-//                                tempSpeed = 2
+//
                                 if(totalClipNum + 1 + clipindex < finallyStuckPoints.count){
                                     deepCopySticker?.speedRate = tempSpeed
                                     
@@ -1077,9 +1077,7 @@ extension PQStuckPointEditerController {
                                     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])
@@ -1111,7 +1109,99 @@ extension PQStuckPointEditerController {
                 if section.sectionType == "normal" {
 
                     BFLog(message: "stuckPoints count is \(finallyStuckPoints.count)")
-                    //已经计算过所有贴纸的累计时长,起点是推荐时长或用户划动后的时间
+                    //一共裁剪的段数
+//                    var totalClipNum:Int = 0
+//                    for sticker in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials() {
+//                        if sticker.type == StickerType.VIDEO.rawValue {
+//                            let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + sticker.locationPath), options: nil)
+//
+//                            var i:Int = 0
+//                            //一个视频切的的段落
+//                            var oneVideoClipNum:Int = 0
+//
+//                            var realUsedMusicDuration = 0.0
+//                            while realUsedMusicDuration <= CMTimeGetSeconds(asset.duration) {
+//                                //快速段
+//                                let LA = maxSpeed * (finallyStuckPoints[i+1] - finallyStuckPoints[i])
+//                                realUsedMusicDuration = realUsedMusicDuration + Float64(LA)
+//                                if(realUsedMusicDuration > CMTimeGetSeconds(asset.duration)){ break}
+//                                oneVideoClipNum = oneVideoClipNum + 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)
+//                                let deepCopySticker = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: stickerjson!)
+//                                // 设置循环模式和适配模式
+//                                deepCopySticker?.generateDefaultValues()
+//                                //当前分段的速度
+//                                var tempSpeed:Float = 1.0
+//
+//                                if(totalClipNum + 1 + clipindex < finallyStuckPoints.count){
+//                                    deepCopySticker?.speedRate = tempSpeed
+//
+//                                    //定义临时使用的变量
+//                                    let tempModel_In = lastOutTime
+//                                    let tempOut = lastOutTime + Float64(tempSpeed) * Float64(finallyStuckPoints[totalClipNum + 1 + clipindex] - finallyStuckPoints[totalClipNum + clipindex])
+//
+//                                    let tempTimelineIn = Float64(finallyStuckPoints[totalClipNum + clipindex])
+//                                    let timelineOut = Float64(finallyStuckPoints[totalClipNum + 1 + clipindex])
+//
+//                                    //处理最后一点视频素材不够卡点时长 e.g. 0.3 卡点时长0.5
+//                                    if(tempOut > realUsedMusicDuration){
+//                                        BFLog(message: "最后一点视频素材不够卡点时长 ")
+//                                        //最后一点素材时长
+//                                        let lastAssetDuration = realUsedMusicDuration - tempOut
+//                                        let pointDuration = timelineOut -  tempTimelineIn
+//                                        let needSpeed = lastAssetDuration / pointDuration
+//                                        //当前卡点段为快速
+//                                        if(tempSpeed >= 1){
+//                                            if(needSpeed > 0.4 * Double(tempSpeed)){
+//                                                deepCopySticker?.speedRate = tempSpeed
+//                                            } else{
+//                                                continue
+//                                            }
+//                                        }else{//当前卡点段为慢速
+//                                            if(needSpeed > 0.4 * Double(tempSpeed) && needSpeed > 0.2){
+//                                                deepCopySticker?.speedRate = tempSpeed
+//                                            } else{
+//                                                continue
+//                                            }
+//                                        }
+//
+//                                    }
+//
+//                                    deepCopySticker?.model_in = tempModel_In
+//                                    deepCopySticker?.out = tempOut
+//
+//                                    deepCopySticker?.timelineIn = tempTimelineIn
+//                                    deepCopySticker?.timelineOut = timelineOut
+//
+//                                    lastOutTime =  deepCopySticker?.out ?? 0
+//
+//                                }
+//                                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!)
+//                                }
+//
+//                            }
+//                            totalClipNum = totalClipNum + oneVideoClipNum - 1
+//                        } else if sticker.type == StickerType.IMAGE.rawValue {
+//                            sticker.generateDefaultValues()
+//                            sticker.timelineIn = Float64(finallyStuckPoints[totalClipNum])
+//                            sticker.timelineOut = Float64(finallyStuckPoints[totalClipNum + 1])
+//                            stickers.append(sticker)
+//                        }
+//                    }
+  ///---
                     var totalStickerTimer:Float64 = CMTimeGetSeconds(playeTimeRange.start)
                     for sticker in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials() {
                         if sticker.type == StickerType.VIDEO.rawValue {