所以我有两个.mp4已经记录并存储在应用程序中,我想将一个附加到另一个,并导出为新视频。它有点奏效,但并不完全!
let composition = AVMutableComposition()
var track = composition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID:Int32(kCMPersistentTrackID_Invalid))
let videoAsset = AVAsset(url: AAA as URL) as AVAsset
let videoAsset2 = AVAsset(url: BBB as URL) as AVAsset
do {
try track?.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset.duration), of: videoAsset.tracks(withMediaType: AVMediaType.video)[0] as AVAssetTrack, at: kCMTimeZero)
try track?.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset.duration), of: videoAsset2.tracks(withMediaType: AVMediaType.video)[0] as AVAssetTrack, at: kCMTimeZero)
} catch {
print("darn")
}
let exporter = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality)
exporter?.outputURL = CCC
exporter?.outputFileType = AVFileType.mp4
exporter?.shouldOptimizeForNetworkUse = true
exporter?.exportAsynchronously {
print("done?")
}
这种组合视频,但它在两个剪辑之间添加了大量的黑屏,并删除了音频。我找不到这个问题的最新答案。谢谢大家的帮助!