Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSStatus error - 12780 when invoking insertTimeRange:ofTrack:atTime:error: of AVMutableCompositionTrack for the second time

Tags:

iphone

video

edit

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.

My problem is this:

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

The method responsible for cutting the video is the following:

- (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:&error];

[compositionAudioTrack insertTimeRange:range 
                               ofTrack:[[_player.currentItem.asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
                                atTime:kCMTimeZero
                                 error:&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];

}

When running the - (void)cutBefore method for the firs time it works fine, when I run it for the second time (the video has been already edited once) the

[compositionVideoTrack insertTimeRange:range 
                           ofTrack:[[_player.currentItem.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
                            atTime:kCMTimeZero
                             error:&error];

and

[compositionAudioTrack insertTimeRange:range 
                           ofTrack:[[_player.currentItem.asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
                            atTime:kCMTimeZero
                             error:&error];

methods returns with the following error:

The operation couldn’t be completed. (OSStatus error -12780.)

I tried to look for what that error code means but found practically nothing.

Thanks for the help

like image 705
Sahar Avatar asked May 11 '11 08:05

Sahar


1 Answers

I faced with this issue and problem was with my calculation for timeRange and startTime parameters of this method. timeRange.start.value and startTime.value must be positive. Maybe my late answer will help someone.

like image 107
Vlad Avatar answered Sep 21 '22 20:09

Vlad