|
@@ -1134,14 +1134,14 @@ extension PQStuckPointEditerController {
|
|
|
if sticker.type == StickerType.VIDEO.rawValue {
|
|
|
let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + sticker.locationPath), options: nil)
|
|
|
|
|
|
- var realUsedMusicDuration = 0.0
|
|
|
+// var realUsedMusicDuration = 0.0
|
|
|
|
|
|
// if(model == .createStickersModelOnlyMusic){
|
|
|
// sticker.clipCount = 1
|
|
|
// }
|
|
|
BFLog(message: "单个视频\(sticker.locationPath)时长::\(CMTimeGetSeconds(asset.duration)) ,clipNum is:\(sticker.clipCount)")
|
|
|
var lastOutTime: Float64 = 0.0
|
|
|
- for clipindex in 0 ... sticker.clipCount - 1 {
|
|
|
+ for clipindex in 0 ... sticker.clipCount {
|
|
|
// deep copy sticker model 防止只有一个对象
|
|
|
let deepCopyStickerDecoderTime: TimeInterval = Date().timeIntervalSince1970
|
|
|
|
|
@@ -1158,44 +1158,36 @@ extension PQStuckPointEditerController {
|
|
|
tempSpeed = (totalClipNum + clipindex) % 2 == 0 ? maxSpeed : minSpeed
|
|
|
}
|
|
|
|
|
|
- if totalClipNum + 1 + clipindex < finallyStuckPoints.count {
|
|
|
+ if totalClipNum + clipindex + 1 < finallyStuckPoints.count {
|
|
|
deepCopySticker?.speedRate = tempSpeed
|
|
|
|
|
|
// 定义临时使用的变量
|
|
|
// 素材分割的开始时间和结束时间
|
|
|
- var tempModel_In = lastOutTime
|
|
|
- var tempOut = lastOutTime + Float64(tempSpeed) * Float64(finallyStuckPoints[totalClipNum + 1 + clipindex] - finallyStuckPoints[totalClipNum + clipindex])
|
|
|
+ let tempModel_In = lastOutTime
|
|
|
+ let tempOut = lastOutTime + Float64(tempSpeed) * Float64(finallyStuckPoints[totalClipNum + 1 + clipindex] - finallyStuckPoints[totalClipNum + clipindex])
|
|
|
// 素材显示的开始时间和结束时间
|
|
|
|
|
|
- var tempTimelineIn = Float64(finallyStuckPoints[totalClipNum + clipindex])
|
|
|
- var timelineOut = Float64(finallyStuckPoints[totalClipNum + 1 + clipindex])
|
|
|
-
|
|
|
-// if model == .createStickersModelOnlyMusic {
|
|
|
-// tempModel_In = 0
|
|
|
-// tempOut = CMTimeGetSeconds(asset.duration)
|
|
|
-//
|
|
|
-// tempTimelineIn = lastOutTime
|
|
|
-//
|
|
|
-// timelineOut = tempTimelineIn + tempOut
|
|
|
-// }
|
|
|
+ let tempTimelineIn = Float64(finallyStuckPoints[totalClipNum + clipindex])
|
|
|
+ let timelineOut = Float64(finallyStuckPoints[totalClipNum + 1 + clipindex])
|
|
|
|
|
|
// 处理最后一点视频素材不够卡点时长 e.g. 0.3 卡点时长0.5
|
|
|
if tempOut > CMTimeGetSeconds(asset.duration) {
|
|
|
BFLog(message: "最后一点视频素材不够卡点时长要做变速C处理 差\(tempOut - CMTimeGetSeconds(asset.duration))")
|
|
|
// 最后一点素材时长
|
|
|
- let lastAssetDuration = realUsedMusicDuration - tempOut
|
|
|
+ let lastAssetDuration = CMTimeGetSeconds(asset.duration) - lastOutTime
|
|
|
let pointDuration = timelineOut - tempTimelineIn
|
|
|
+ // 要适应到卡点内要使用的C速度
|
|
|
let needSpeed = lastAssetDuration / pointDuration
|
|
|
// 当前卡点段为快速
|
|
|
if tempSpeed >= 1 {
|
|
|
- if needSpeed > 0.4 * Double(tempSpeed) {
|
|
|
- deepCopySticker?.speedRate = tempSpeed
|
|
|
+ if needSpeed >= 0.4 * Double(tempSpeed) {
|
|
|
+ deepCopySticker?.speedRate = Float(needSpeed)
|
|
|
} else {
|
|
|
continue
|
|
|
}
|
|
|
} else { // 当前卡点段为慢速
|
|
|
- if needSpeed > 0.4 * Double(tempSpeed) && needSpeed > 0.2 {
|
|
|
- deepCopySticker?.speedRate = tempSpeed
|
|
|
+ if needSpeed >= 0.4 * Double(tempSpeed) && needSpeed >= 0.2 {
|
|
|
+ deepCopySticker?.speedRate = Float(needSpeed)
|
|
|
} else {
|
|
|
continue
|
|
|
}
|
|
@@ -1442,17 +1434,50 @@ extension PQStuckPointEditerController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 3,多补一个卡点 做 C级 速处理
|
|
|
+ // 3,多补一个卡点 做 C级 速处理,要根据条件不满足 不用补位
|
|
|
if useAssestDurationTemp < assetDuration {
|
|
|
|
|
|
+ //下一个卡的的速度性质快、慢
|
|
|
+ var tempSpeed: Float = 1.0
|
|
|
+ if model == .createStickersModelSpeed {
|
|
|
+ tempSpeed = (sticker.clipCount) % 2 == 0 ? maxSpeed : minSpeed
|
|
|
+ }
|
|
|
+ // 最后一点素材时长
|
|
|
+ let lastAssetDuration = Float(CMTimeGetSeconds(asset.duration)) - useAssestDurationTemp
|
|
|
+
|
|
|
lastPointIndex = sticker.clipCount % stuckPointsTemp.count
|
|
|
+ //两个卡点
|
|
|
let a = stuckPointsTemp[lastPointIndex ?? 0]
|
|
|
+ var b:Float = 0.0
|
|
|
if((lastPointIndex ?? 0) + 1 < stuckPointsTemp.count){
|
|
|
- let b = stuckPointsTemp[(lastPointIndex ?? 0) + 1]
|
|
|
- finallyStuckPoints.append((finallyStuckPoints.last ?? 0.0) + (b - a))
|
|
|
-
|
|
|
- sticker.clipCount = sticker.clipCount + 1
|
|
|
+ b = stuckPointsTemp[(lastPointIndex ?? 0) + 1]
|
|
|
+
|
|
|
+ let pointDuration = b - a
|
|
|
+ // 要适应到卡点内要使用的C速度
|
|
|
+ let needSpeed = lastAssetDuration / pointDuration
|
|
|
+
|
|
|
+ // 当前卡点段为快速
|
|
|
+ if tempSpeed >= 1 {
|
|
|
+ if needSpeed >= 0.4 * tempSpeed {
|
|
|
+ //要补位
|
|
|
+ finallyStuckPoints.append((finallyStuckPoints.last ?? 0.0) + (b - 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
|
|
|
+ }else{
|
|
|
+ BFLog(message: "条件不满足不用补位")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|