|
@@ -29,10 +29,10 @@ class DubbingComposer {
|
|
|
let composition = AVMutableComposition()
|
|
let composition = AVMutableComposition()
|
|
|
|
|
|
|
|
var videoTimeRange:CMTimeRange?
|
|
var videoTimeRange:CMTimeRange?
|
|
|
- let videoTrack = composition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: kCMPersistentTrackID_Invalid)
|
|
|
|
|
|
|
|
|
|
//为合成器添加视频轨道
|
|
//为合成器添加视频轨道
|
|
|
if((videoUrl) != nil){
|
|
if((videoUrl) != nil){
|
|
|
|
|
+ let videoTrack = composition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: kCMPersistentTrackID_Invalid)
|
|
|
let videoAsset = AVURLAsset(url: videoUrl!, options: nil)
|
|
let videoAsset = AVURLAsset(url: videoUrl!, options: nil)
|
|
|
videoTimeRange = CMTimeRangeMake(start: CMTime.zero, duration: videoAsset.duration)
|
|
videoTimeRange = CMTimeRangeMake(start: CMTime.zero, duration: videoAsset.duration)
|
|
|
do {
|
|
do {
|
|
@@ -95,14 +95,21 @@ class DubbingComposer {
|
|
|
assetExport.outputFileType = AVFileType.mp4
|
|
assetExport.outputFileType = AVFileType.mp4
|
|
|
assetExport.outputURL = output
|
|
assetExport.outputURL = output
|
|
|
assetExport.shouldOptimizeForNetworkUse = true
|
|
assetExport.shouldOptimizeForNetworkUse = true
|
|
|
- assetExport.exportAsynchronously(completionHandler: {
|
|
|
|
|
- successBlock?()
|
|
|
|
|
|
|
+ assetExport.exportAsynchronously(completionHandler: {
|
|
|
|
|
+ if((assetExport.error) != nil){
|
|
|
|
|
+ print(assetExport.error!)
|
|
|
|
|
+ DispatchQueue.main.async(execute: {
|
|
|
|
|
+ failBlock?("Something wrong on composition")
|
|
|
|
|
+ })
|
|
|
|
|
+ }else{
|
|
|
|
|
+ successBlock?()
|
|
|
|
|
+ }
|
|
|
return
|
|
return
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- DispatchQueue.main.async(execute: {
|
|
|
|
|
|
|
+ DispatchQueue.main.async(execute: {
|
|
|
failBlock?("Something wrong on composition")
|
|
failBlock?("Something wrong on composition")
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|