Browse Source

1,多个视频少素材问题 2, 多个视频最后一段重复问题

jsonwang 3 years ago
parent
commit
d7765d9e5d

+ 59 - 13
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -1152,6 +1152,7 @@ extension PQStuckPointEditerController {
                                     BFLog(message: "生成stickers 总时长为 aaa\(Date().timeIntervalSince1970 - deepCopyStickerDecoderTime)")
                                     // 设置循环模式和适配模式
                                     deepCopySticker?.generateDefaultValues()
+                                    deepCopySticker?.materialDurationFit?.fitType = adapterMode.staticFrame.rawValue
                                     // 当前分段的速度
                                     var tempSpeed: Float = 1.0
                                     if model == .createStickersModelSpeed {
@@ -1164,7 +1165,7 @@ extension PQStuckPointEditerController {
                                         // 定义临时使用的变量
                                         // 素材分割的开始时间和结束时间
                                         let tempModel_In = lastOutTime
-                                        let tempOut = lastOutTime + Float64(tempSpeed) * Float64(finallyStuckPoints[totalClipNum + 1 + clipindex] - finallyStuckPoints[totalClipNum + clipindex])
+                                        var tempOut = lastOutTime + Float64(tempSpeed) * Float64(finallyStuckPoints[totalClipNum + 1 + clipindex] - finallyStuckPoints[totalClipNum + clipindex])
                                         // 素材显示的开始时间和结束时间
                                         
                                         let tempTimelineIn = Float64(finallyStuckPoints[totalClipNum + clipindex])
@@ -1192,6 +1193,8 @@ extension PQStuckPointEditerController {
                                                     continue
                                                 }
                                             }
+                                            
+                                            tempOut =  CMTimeGetSeconds(asset.duration)
                                         }
 
                                         deepCopySticker?.model_in = tempModel_In
@@ -1203,13 +1206,13 @@ extension PQStuckPointEditerController {
                                         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)")
+                                    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 + sticker.clipCount - 1
+                                totalClipNum = totalClipNum + sticker.clipCount
                             } else if sticker.type == StickerType.IMAGE.rawValue {
                                 if totalClipNum + 1 >= finallyStuckPoints.count {
                                     BFLog(message: "数据出现错误!!!查正")
@@ -1382,7 +1385,7 @@ extension PQStuckPointEditerController {
 
                             // 查找使用的最后一个卡点在原数组中的位置
                             var lastPointIndex = stuckPointsTemp.firstIndex(where: { (point) -> Bool in
-                                (point == (finallyStuckPoints.last ?? 0).truncatingRemainder(dividingBy: (stuckPointsTemp.last ?? 0)))
+                                (point == (finallyStuckPoints.last ?? 0.0).truncatingRemainder(dividingBy: (stuckPointsTemp.last ?? 0)))
                             })
                             var i = lastPointIndex ?? 0
                             // 1,计算 AB 段的个数
@@ -1430,8 +1433,9 @@ extension PQStuckPointEditerController {
                             for i in pointStartIndex ... (sticker.clipCount + pointStartIndex){
                                 
                                 if(i < stuckPointsTemp.count){
-                                    BFLog(message: "直接添加")
+                                    BFLog(message: "直接添加值前:\(stuckPointsTemp[i])")
                                     finallyStuckPoints.append(stuckPointsTemp[i])
+                                    BFLog(message: "直接添加值后:\(finallyStuckPoints.last ?? 0.0)")
                                 }else{
                                     let duration = (stuckPointsTemp.last ?? 0.0) - (stuckPointsTemp.first ?? 0.0)
                                     let index = i % stuckPointsTemp.count
@@ -1454,9 +1458,9 @@ extension PQStuckPointEditerController {
                                 // 最后一点素材时长
                                 let lastAssetDuration = Float(CMTimeGetSeconds(asset.duration)) - useAssestDurationTemp
                                 
-                                lastPointIndex = sticker.clipCount % stuckPointsTemp.count
+                                lastPointIndex = (sticker.clipCount % stuckPointsTemp.count) ?? 0
                                 //两个卡点
-                                let a = stuckPointsTemp[lastPointIndex ?? 0]
+                                let a:Float = stuckPointsTemp[lastPointIndex ?? 0]
                                 var b:Float = 0.0
                                 if((lastPointIndex ?? 0) + 1 < stuckPointsTemp.count){
                                     b = stuckPointsTemp[(lastPointIndex ?? 0) + 1]
@@ -1468,17 +1472,59 @@ extension PQStuckPointEditerController {
                                     // 当前卡点段为快速
                                     if tempSpeed >= 1 {
                                         if needSpeed >= 0.4 * tempSpeed {
-                                            //要补位
-                                            finallyStuckPoints.append((finallyStuckPoints.last ?? 0.0) + (b - a))
-                                            sticker.clipCount = sticker.clipCount + 1
+                                            // 这里代码要整理
+                                            // 查找使用的最后一个卡点在原数组中的位置
+                                            var lastPointIndex = stuckPointsTemp.firstIndex(where: { (point) -> Bool in
+                                                (point == (finallyStuckPoints.last ?? 0.0).truncatingRemainder(dividingBy: (stuckPointsTemp.last ?? 0)))
+                                            })
+                                            for i in ((lastPointIndex ?? 0) + 1) ... ((lastPointIndex ?? 0) + 1){
+                                                
+                                                if(i < stuckPointsTemp.count){
+                                                    BFLog(message: "直接添加值前:\(stuckPointsTemp[i])")
+                                                    finallyStuckPoints.append(stuckPointsTemp[i])
+                                                    sticker.clipCount = sticker.clipCount + 1
+                                                    BFLog(message: "直接添加值后:\(finallyStuckPoints.last ?? 0.0)")
+                                                }else{
+                                                    let duration = (stuckPointsTemp.last ?? 0.0) - (stuckPointsTemp.first ?? 0.0)
+                                                    let index = i % stuckPointsTemp.count
+                                                    if((index + 1) < stuckPointsTemp.count){
+                                                        let a = duration * Float((i / stuckPointsTemp.count)) + stuckPointsTemp[index + 1]
+                                                        finallyStuckPoints.append(a)
+                                                        sticker.clipCount = sticker.clipCount + 1
+                                                    }
+                                                    
+                                                }
+                                            }
+                                            
+                                          
                                         }else{
                                             BFLog(message: "条件不满足不用补位")
                                         }
                                     } else { // 当前卡点段为慢速
                                         if needSpeed >= 0.4 * tempSpeed && needSpeed >= 0.2 {
-                                            //要补位
-                                            finallyStuckPoints.append((finallyStuckPoints.last ?? 0.0) + (b - a))
-                                            sticker.clipCount = sticker.clipCount + 1
+                                            // 查找使用的最后一个卡点在原数组中的位置
+                                            var lastPointIndex = stuckPointsTemp.firstIndex(where: { (point) -> Bool in
+                                                (point == (finallyStuckPoints.last ?? 0.0).truncatingRemainder(dividingBy: (stuckPointsTemp.last ?? 0)))
+                                            })
+                                            for i in ((lastPointIndex ?? 0) + 1) ... ((lastPointIndex ?? 0) + 1){
+                                                
+                                                if(i < stuckPointsTemp.count){
+                                                    BFLog(message: "直接添加值前:\(stuckPointsTemp[i])")
+                                                    finallyStuckPoints.append(stuckPointsTemp[i])
+                                                    sticker.clipCount = sticker.clipCount + 1
+                                                    BFLog(message: "直接添加值后:\(finallyStuckPoints.last ?? 0.0)")
+                                                }else{
+                                                    let duration = (stuckPointsTemp.last ?? 0.0) - (stuckPointsTemp.first ?? 0.0)
+                                                    let index = i % stuckPointsTemp.count
+                                                    if((index + 1) < stuckPointsTemp.count){
+                                                        let a = duration * Float((i / stuckPointsTemp.count)) + stuckPointsTemp[index + 1]
+                                                        finallyStuckPoints.append(a)
+                                                        sticker.clipCount = sticker.clipCount + 1
+                                                    }
+                                                    
+                                                }
+                                            }
+                                            
                                         }else{
                                             BFLog(message: "条件不满足不用补位")
                                         }