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
You also need to update
atvalue, I’d advise you to move that line after insertTime update and use new value, to remove duplicate work here
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.