|
@@ -22,9 +22,9 @@ public class BFRecordExport {
|
|
|
// 录音段
|
|
|
public var voiceList:[PQVoiceModel]? {
|
|
|
didSet {
|
|
|
- audioAssets = voiceList?.map({ model in
|
|
|
- AVURLAsset(url: URL(fileURLWithPath: model.wavFilePath))
|
|
|
- })
|
|
|
+// audioAssets = voiceList?.map({ model in
|
|
|
+// AVURLAsset(url: URL(fileURLWithPath: model.wavFilePath))
|
|
|
+// })
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -54,9 +54,10 @@ public class BFRecordExport {
|
|
|
bgMovieInfo.canvasFillType = stickerContentMode.aspectFitStr.rawValue
|
|
|
bgMovieInfo.volumeGain = 30
|
|
|
bgMovieInfo.aptDuration = bgMovieInfo.timelineOut
|
|
|
+ bgMovieInfo.duration = bgMovieInfo.timelineOut
|
|
|
mStickers.append(bgMovieInfo)
|
|
|
|
|
|
- beginExport(videoStickers: mStickers, audioAsset: self.audioAssets)
|
|
|
+ beginExport(videoStickers: mStickers)
|
|
|
}
|
|
|
|
|
|
public func cancelExport(){
|
|
@@ -109,7 +110,7 @@ public class BFRecordExport {
|
|
|
}
|
|
|
|
|
|
|
|
|
- func beginExport(videoStickers:[PQEditVisionTrackMaterialsModel], audioAsset: [AVURLAsset]?) {
|
|
|
+ func beginExport(videoStickers:[PQEditVisionTrackMaterialsModel]) {
|
|
|
// 输出视频地址
|
|
|
// exprotVideo()
|
|
|
// return;
|
|
@@ -122,45 +123,44 @@ public class BFRecordExport {
|
|
|
BFLog(1, message: "导出视频地址 \(outPutMP4URL)")
|
|
|
|
|
|
// 处理导出
|
|
|
- if (audioAsset?.count ?? 0 ) > 0 || videoStickers.count > 1 {
|
|
|
- var audioUrl:URL?
|
|
|
- if audioAsset?.count ?? 0 > 0 {
|
|
|
- // 多音频合成
|
|
|
- if let list = voiceList?.map({ model in
|
|
|
- URL(fileURLWithPath: model.wavFilePath)
|
|
|
- }){
|
|
|
- if list.count == 1 {
|
|
|
- audioUrl = list.first
|
|
|
- }else {
|
|
|
- let semaphore = DispatchSemaphore(value: 0)
|
|
|
- PQPlayerViewModel.mergeAudios(urls: list) { completURL in
|
|
|
- audioUrl = completURL
|
|
|
- semaphore.signal()
|
|
|
- }
|
|
|
- _ = semaphore.wait(timeout: .now() + 5)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 每次初始化的时候设置初始值 为 nIl
|
|
|
- var audioMix: AVMutableAudioMix?
|
|
|
- var composition: AVMutableComposition?
|
|
|
-
|
|
|
+ if (voiceList?.count ?? 0 ) > 0 || videoStickers.count > 1 {
|
|
|
+// var audioUrl:URL?
|
|
|
+// if audioAsset?.count ?? 0 > 0 {
|
|
|
+// // 多音频合成
|
|
|
+// if let list = voiceList?.map({ model in
|
|
|
+// URL(fileURLWithPath: model.wavFilePath)
|
|
|
+// }){
|
|
|
+// if list.count == 1 {
|
|
|
+// audioUrl = list.first
|
|
|
+// }else {
|
|
|
+// let semaphore = DispatchSemaphore(value: 0)
|
|
|
+// PQPlayerViewModel.mergeAudios(urls: list) { completURL in
|
|
|
+// audioUrl = completURL
|
|
|
+// semaphore.signal()
|
|
|
+// }
|
|
|
+// _ = semaphore.wait(timeout: .now() + 5)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ let (audioMix, composition) = mergeAudio(videoStickers: videoStickers, audios: voiceList)
|
|
|
+
|
|
|
let filter = mStickers.map { sticker in
|
|
|
PQMovieFilter(movieSticker: sticker)
|
|
|
}
|
|
|
// 有
|
|
|
- if let completURL = audioUrl {
|
|
|
- let inputAsset = AVURLAsset(url: completURL, options: avAssertOptions)
|
|
|
-// (audioMix, composition) = PQVideoEditViewModel.setupAudioMix(originAsset: inputAsset, bgmData: nil, videoStickers: videoStickers)
|
|
|
- //使用原视频无音版
|
|
|
- (audioMix, composition) = PQVideoEditViewModel.setupAudioMix(originAsset: inputAsset, bgmData: nil, videoStickers: nil)
|
|
|
-
|
|
|
- if composition != nil {
|
|
|
- exporter = PQCompositionExporter(asset: composition!, videoComposition: nil, audioMix: audioMix, filters: filter, animationTool: nil, exportURL: outPutMP4URL)
|
|
|
- }else {
|
|
|
- exporter = PQCompositionExporter(asset: inputAsset, videoComposition: nil, audioMix: nil, filters: filter, animationTool: nil, exportURL: outPutMP4URL)
|
|
|
- }
|
|
|
- }
|
|
|
+// if let completURL = audioUrl {
|
|
|
+// let inputAsset = AVURLAsset(url: completURL, options: avAssertOptions)
|
|
|
+//// (audioMix, composition) = PQVideoEditViewModel.setupAudioMix(originAsset: inputAsset, bgmData: nil, videoStickers: videoStickers)
|
|
|
+// //使用原视频无音版
|
|
|
+// (audioMix, composition) = PQVideoEditViewModel.setupAudioMix(originAsset: inputAsset, bgmData: nil, videoStickers: nil)
|
|
|
+//
|
|
|
+// if composition != nil {
|
|
|
+// exporter = PQCompositionExporter(asset: composition!, videoComposition: nil, audioMix: audioMix, filters: filter, animationTool: nil, exportURL: outPutMP4URL)
|
|
|
+// }else {
|
|
|
+// exporter = PQCompositionExporter(asset: inputAsset, videoComposition: nil, audioMix: nil, filters: filter, animationTool: nil, exportURL: outPutMP4URL)
|
|
|
+// }
|
|
|
+// }
|
|
|
+ exporter = PQCompositionExporter(asset: composition, videoComposition: nil, audioMix: audioMix, filters: filter, animationTool: nil, exportURL: outPutMP4URL)
|
|
|
|
|
|
let size = getVideoSize()
|
|
|
var orgeBitRate = Int(size.width * size.height * 3)
|
|
@@ -243,3 +243,44 @@ public class BFRecordExport {
|
|
|
return size
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+extension BFRecordExport {
|
|
|
+ func mergeAudio(videoStickers:[PQEditVisionTrackMaterialsModel], audios:[PQVoiceModel]?) -> (AVMutableAudioMix, AVMutableComposition){
|
|
|
+ let composition = AVMutableComposition()
|
|
|
+ let audioMix = AVMutableAudioMix()
|
|
|
+ var tempParameters = [AVMutableAudioMixInputParameters]()
|
|
|
+
|
|
|
+ var totalDuration : Float64 = 0
|
|
|
+ for sticker in videoStickers {
|
|
|
+ if sticker.volumeGain == 0 {
|
|
|
+ // 如果添加了会有刺啦音
|
|
|
+ BFLog(message: "音频音量 为0 不添加")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ sticker.volumeGain = 2
|
|
|
+ totalDuration = max(totalDuration, sticker.duration)
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ audioMix.inputParameters = tempParameters
|
|
|
+ return (audioMix, composition)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|