Swift Merge AVasset-Videos array

后端 未结 3 1879
忘了有多久
忘了有多久 2021-02-04 20:18

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

3条回答
  •  臣服心动
    2021-02-04 20:56

    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)
    

提交回复
热议问题