I want to merge the AVAsset-arrayVideos
into one single video and save it on camera roll. Raywenderlich.com has a great tutorial where two videos are merged into on
You don't need atTimeM at all, since you are simply marching completeTrackDuration along it is where the next piece should be added. So replace
if videoAsset == arrayVideos.first{
atTimeM = kCMTimeZero
} else{
atTimeM = lastAsset!.duration
}
try videoTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset.duration), of: videoAsset.tracks(withMediaType: AVMediaTypeVideo)[0], at: atTimeM)
with
try videoTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset.duration), of: videoAsset.tracks(withMediaType: AVMediaTypeVideo)[0], at: completeTrackDuration)