So I have two .mp4s already recorded and stored in app, and I want to append one to the other, and export as a new video. It sort of works, but not quite!
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?")
}
This sort of combines the videos, but it adds massive chunks of black screen in between the two clips, and removes the audio. I cannot find any recent answers to this problem. Thanks for all help!