Trouble applying scaleTimeRange on multiple videos in a AVMutableComposition video

  1. After you scale the video, duration of the composition gets recalculated, so you need to append the next part according to this change. Replace

     insertTime = insertTime + duration


     insertTime = insertTime + newDuration
  2. You also need to update setOpacity at value, I’d advise you to move that line after insertTime update and use new value, to remove duplicate work here

  3. When you’re applying scale, it’s applied to new composition, so you need to use relative range:

     let currentRange = CMTimeRange(start: insertTime, duration: frameRange.duration)
     nthVideoTrack.scaleTimeRange(currentRange, toDuration: newDuration)
     nthAudioTrack.scaleTimeRange(currentRange, toDuration: newDuration)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top