|
@@ -54,33 +54,27 @@ public class BFRecordExport {
|
|
|
let asset = itemModel.baseMaterial
|
|
|
if let dur = asset?.duration.seconds {
|
|
|
if synthesisAll {
|
|
|
- let bgMovieInfo = splitBaseMaterial(range: CMTimeRange(start: CMTime(seconds: totalDur*100, preferredTimescale: 100), duration: CMTime(seconds: dur*100, preferredTimescale: 100)))
|
|
|
+ let bgMovieInfo = splitBaseMaterial(timelineIn: totalDur, model_in: 0, duration: dur)
|
|
|
+ bgMovieInfo.volumeGain = 0
|
|
|
itemModel.videoStickers.append(bgMovieInfo)
|
|
|
totalDur += dur
|
|
|
} else {
|
|
|
var subDur = 0.0
|
|
|
- for range in itemModel.dealedDurationRanges {
|
|
|
- let sticker = splitBaseMaterial(range: CMTimeRange(start: CMTime(seconds: (totalDur + subDur) * 100, preferredTimescale: 100), duration: CMTime(seconds: range.duration.seconds * 100, preferredTimescale: 100)))
|
|
|
+ let drangs = itemModel.dealedDurationRanges.filter { ranges in
|
|
|
+ ranges.isRecord == true
|
|
|
+ }
|
|
|
+ for srange in drangs {
|
|
|
+ let range = srange.range
|
|
|
+ let sticker = splitBaseMaterial(timelineIn: (totalDur + subDur), model_in: range.start.seconds, duration: range.duration.seconds)
|
|
|
sticker.volumeGain = 0
|
|
|
itemModel.videoStickers.append(sticker)
|
|
|
- subDur += range.start.seconds
|
|
|
+ subDur += range.duration.seconds
|
|
|
}
|
|
|
totalDur += subDur
|
|
|
}
|
|
|
}
|
|
|
-// let bgMovieInfo: PQEditVisionTrackMaterialsModel = PQEditVisionTrackMaterialsModel()
|
|
|
-// bgMovieInfo.type = StickerType.VIDEO.rawValue
|
|
|
-// bgMovieInfo.locationPath = ((asset?.url.absoluteString)?.removingPercentEncoding ?? "").replacingOccurrences(of: "file://", with: "")
|
|
|
-// bgMovieInfo.timelineIn = 0
|
|
|
-// bgMovieInfo.timelineOut = CMTimeGetSeconds(asset?.duration ?? CMTime.zero)
|
|
|
-// bgMovieInfo.model_in = bgMovieInfo.timelineIn
|
|
|
-// bgMovieInfo.out = bgMovieInfo.timelineOut
|
|
|
-// bgMovieInfo.canvasFillType = stickerContentMode.aspectFitStr.rawValue
|
|
|
-// bgMovieInfo.volumeGain = 30
|
|
|
-// bgMovieInfo.aptDuration = bgMovieInfo.timelineOut
|
|
|
-// bgMovieInfo.duration = bgMovieInfo.timelineOut
|
|
|
- beginExport()
|
|
|
}
|
|
|
+ beginExport(synthesisAll:synthesisAll)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -119,15 +113,15 @@ public class BFRecordExport {
|
|
|
return ranges
|
|
|
}
|
|
|
|
|
|
- func splitBaseMaterial(range:CMTimeRange) -> PQEditVisionTrackMaterialsModel{
|
|
|
+ func splitBaseMaterial(timelineIn:Double, model_in:Double, duration:Double) -> PQEditVisionTrackMaterialsModel{
|
|
|
let bgMovieInfo: PQEditVisionTrackMaterialsModel = PQEditVisionTrackMaterialsModel()
|
|
|
if let asset = data?.first?.baseMaterial {
|
|
|
bgMovieInfo.type = StickerType.VIDEO.rawValue
|
|
|
bgMovieInfo.locationPath = ((asset.url.absoluteString).removingPercentEncoding ?? "").replacingOccurrences(of: "file://", with: "")
|
|
|
- bgMovieInfo.timelineIn = range.start.seconds
|
|
|
- bgMovieInfo.timelineOut = range.end.seconds
|
|
|
- bgMovieInfo.model_in = bgMovieInfo.timelineIn
|
|
|
- bgMovieInfo.out = bgMovieInfo.timelineOut
|
|
|
+ bgMovieInfo.timelineIn = timelineIn
|
|
|
+ bgMovieInfo.timelineOut = timelineIn + duration
|
|
|
+ bgMovieInfo.model_in = model_in
|
|
|
+ bgMovieInfo.out = model_in + duration
|
|
|
bgMovieInfo.canvasFillType = stickerContentMode.aspectFitStr.rawValue
|
|
|
bgMovieInfo.volumeGain = 1
|
|
|
bgMovieInfo.aptDuration = bgMovieInfo.timelineOut
|
|
@@ -137,7 +131,7 @@ public class BFRecordExport {
|
|
|
return bgMovieInfo
|
|
|
}
|
|
|
|
|
|
- func beginExport() {
|
|
|
+ func beginExport(synthesisAll:Bool) {
|
|
|
// 输出视频地址
|
|
|
// exprotVideo()
|
|
|
// return;
|
|
@@ -155,10 +149,9 @@ public class BFRecordExport {
|
|
|
// 处理导出
|
|
|
let voiceList = itemModel.voiceStickers
|
|
|
let videoStickers = itemModel.videoStickers
|
|
|
-
|
|
|
if voiceList.count > 0 || videoStickers.count > 1 {
|
|
|
|
|
|
- let (audioMix, composition) = mergeAudio(videoStickers: videoStickers, audios: voiceList)
|
|
|
+ let (audioMix, composition) = mergeAudio(videoStickers: videoStickers, audios: voiceList,synthesisAll:synthesisAll)
|
|
|
|
|
|
let filter = videoStickers.map { sticker in
|
|
|
PQMovieFilter(movieSticker: sticker)
|
|
@@ -196,7 +189,7 @@ public class BFRecordExport {
|
|
|
|
|
|
BFLog(message: "导出设置的码率为:\(orgeBitRate)")
|
|
|
if exporter!.prepare(videoSize: size, videoAverageBitRate: orgeBitRate) {
|
|
|
- exporter!.start(playeTimeRange: CMTimeRange(start: CMTime.zero, end: asset?.duration ?? CMTime.zero))
|
|
|
+ exporter!.start(playeTimeRange: CMTimeRange(start: CMTime.zero, end: composition.duration))
|
|
|
}
|
|
|
exporter?.progressClosure = { [weak self] _, _, progress in
|
|
|
// BFLog(message: "正片合成进度 \(progress * 100)%")
|
|
@@ -267,7 +260,7 @@ public class BFRecordExport {
|
|
|
}
|
|
|
|
|
|
extension BFRecordExport {
|
|
|
- func mergeAudio(videoStickers:[PQEditVisionTrackMaterialsModel], audios:[PQVoiceModel]?) -> (AVMutableAudioMix, AVMutableComposition){
|
|
|
+ func mergeAudio(videoStickers:[PQEditVisionTrackMaterialsModel], audios:[PQVoiceModel]?, synthesisAll:Bool) -> (AVMutableAudioMix, AVMutableComposition){
|
|
|
let composition = AVMutableComposition()
|
|
|
let audioMix = AVMutableAudioMix()
|
|
|
var tempParameters = [AVMutableAudioMixInputParameters]()
|
|
@@ -284,25 +277,62 @@ extension BFRecordExport {
|
|
|
tempParameters += PQVideoEditViewModel.dealWithMaterialTrack(stickerModel: sticker, composition: composition)
|
|
|
}
|
|
|
if let voices = audios {
|
|
|
- for model in voices {
|
|
|
- if model.volume == 0 {
|
|
|
- // 如果添加了会有刺啦音
|
|
|
- BFLog(message: "音频音量 为0 不添加")
|
|
|
- continue
|
|
|
- }
|
|
|
- let sticker = PQEditVisionTrackMaterialsModel()
|
|
|
- sticker.model_in = 0
|
|
|
- sticker.timelineIn = model.startTime
|
|
|
- sticker.out = model.endTime
|
|
|
- sticker.aptDuration = model.endTime - model.startTime
|
|
|
- sticker.duration = sticker.aptDuration
|
|
|
- sticker.locationPath = model.wavFilePath
|
|
|
- sticker.volumeGain = 100 //Float64(model.volume)
|
|
|
- tempParameters += PQVideoEditViewModel.dealWithMaterialTrack(stickerModel: sticker, composition: composition)
|
|
|
+ if synthesisAll {
|
|
|
+ tempParameters += mergeRecordVoiceAll(voices:voices, composition)
|
|
|
+ }else {
|
|
|
+ tempParameters += mergeRecordVoiceOnly(voices:voices, composition)
|
|
|
}
|
|
|
}
|
|
|
audioMix.inputParameters = tempParameters
|
|
|
return (audioMix, composition)
|
|
|
}
|
|
|
|
|
|
+ func mergeRecordVoiceOnly(voices:[PQVoiceModel], _ composition:AVMutableComposition) -> [AVMutableAudioMixInputParameters] {
|
|
|
+ var tempParameters = [AVMutableAudioMixInputParameters]()
|
|
|
+ var totalDur:Double = 0.0
|
|
|
+ for model in voices {
|
|
|
+ if model.volume == 0 {
|
|
|
+ // 如果添加了会有刺啦音
|
|
|
+ BFLog(message: "音频音量 为0 不添加")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ let duration = model.endTime - model.startTime
|
|
|
+
|
|
|
+ let sticker = PQEditVisionTrackMaterialsModel()
|
|
|
+ sticker.model_in = 0
|
|
|
+ sticker.out = duration
|
|
|
+ sticker.timelineIn = totalDur
|
|
|
+ sticker.aptDuration = duration
|
|
|
+ sticker.duration = duration
|
|
|
+ sticker.locationPath = model.wavFilePath
|
|
|
+ sticker.volumeGain = 100 //Float64(model.volume)
|
|
|
+ tempParameters += PQVideoEditViewModel.dealWithMaterialTrack(stickerModel: sticker, composition: composition)
|
|
|
+ totalDur += duration
|
|
|
+ }
|
|
|
+
|
|
|
+ return tempParameters
|
|
|
+ }
|
|
|
+
|
|
|
+ func mergeRecordVoiceAll(voices:[PQVoiceModel], _ composition:AVMutableComposition) -> [AVMutableAudioMixInputParameters] {
|
|
|
+ var tempParameters = [AVMutableAudioMixInputParameters]()
|
|
|
+ for model in voices {
|
|
|
+ if model.volume == 0 {
|
|
|
+ // 如果添加了会有刺啦音
|
|
|
+ BFLog(message: "音频音量 为0 不添加")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ let sticker = PQEditVisionTrackMaterialsModel()
|
|
|
+ sticker.model_in = 0
|
|
|
+ sticker.timelineIn = model.startTime
|
|
|
+ sticker.out = model.endTime
|
|
|
+ sticker.aptDuration = model.endTime - model.startTime
|
|
|
+ sticker.duration = sticker.aptDuration
|
|
|
+ sticker.locationPath = model.wavFilePath
|
|
|
+ sticker.volumeGain = 100 //Float64(model.volume)
|
|
|
+ tempParameters += PQVideoEditViewModel.dealWithMaterialTrack(stickerModel: sticker, composition: composition)
|
|
|
+ }
|
|
|
+
|
|
|
+ return tempParameters
|
|
|
+ }
|
|
|
+
|
|
|
}
|