Search code examples
swiftavfoundationavmutablecomposition

Do all following tracks need to be updated in a mutable composition if a track is removed?


To add a time range to an AVMutableCompositionTrack you have to specify the start time in the track (at:)...

  try track?.insertTimeRange(CMTimeRangeMake(start: CMTime.zero,
                                             duration: CMTime(seconds: 2, preferredTimescale: CMTimeScale(1))),
                             of: asset.tracks(withMediaType: .video)[0],
                             at: composition.duration)

Let's say I have several tracks in a mutable composition such that their time ranges play in a sequence with no gaps. If I remove, say, the second track, then do all the following tracks need to have their start time manually updated? Similarly, do all the track instructions need to be updated too? Or is there a way of having this happen automatically?


Solution

  • Tracks are not like a rosary that when you grab a few seeds the other ones shift automatically , yes you have to update the times manually in the mutable composition and the instructions