title: OSStatus error - 12780 when invoking insertTimeRange:ofTrack:atTime:error: of AVMutableCompositionTrack for the second time
body: <p>First of all I have to say that I love this forum, it helped me so many time. 
  I have a problem and I couldn't find an answer to it anywhere so this is my first question here.</p>
  
  <p>My problem is this:</p>
  
  <p>I have a video represented by AVPlayerItem, the user can edit the video start time using the cutBefore button that cuts the video to the left of the slider</p>
  
  <p>The method responsible for cutting the video is the following:</p>
  
  <pre><code>- (void)CutBeforeAction { 
  
  AVMutableComposition *composition = [AVMutableComposition composition];
  
  // Get the audio and video tracks of the video
  AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
  AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
  
  // Calculate the new duration
  CMTime currStartTime = _player.currentItem.currentTime;
  CMTime endTime = _player.currentItem.duration;
  CMTimeRange range = CMTimeRangeFromTimeToTime(currStartTime, endTime);
  
  // Insert the new duration to the tracks
  NSError *error = nil;
  [compositionVideoTrack insertTimeRange:range 
                                 ofTrack:[[_player.currentItem.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
                                  atTime:kCMTimeZero
                                   error:&amp;error];
  
  [compositionAudioTrack insertTimeRange:range 
                                 ofTrack:[[_player.currentItem.asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
                                  atTime:kCMTimeZero
                                   error:&amp;error];
  // Create a new AVPlayerItem with the new composition
  AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:composition];
  [self setPlayerItem:item];
  [_player replaceCurrentItemWithPlayerItem:item];
  
  // change the player location to the beginning of the video
  [_player seekToTime:CMTimeMakeWithSeconds(0, 1)];
  [self syncTimeLabel];
  [self syncScrubber];
  </code></pre>
  
  <p>}</p>
  
  <p>When running the <code>- (void)cutBefore</code> method for the firs time it works fine, when I run it for the second time (the video has been already edited once) the</p>
  
  <pre><code>[compositionVideoTrack insertTimeRange:range 
                             ofTrack:[[_player.currentItem.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
                              atTime:kCMTimeZero
                               error:&amp;error];
  </code></pre>
  
  <p>and</p>
  
  <pre><code>[compositionAudioTrack insertTimeRange:range 
                             ofTrack:[[_player.currentItem.asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
                              atTime:kCMTimeZero
                               error:&amp;error];
  </code></pre>
  
  <p>methods returns with the following error:</p>
  
  <p><strong>The operation couldn’t be completed. (OSStatus error -12780.)</strong></p>
  
  <p>I tried to look for what that error code means but found practically nothing.</p>
  
  <p>Thanks for the help</p>