OSStatus error - 12780 when calling insertTimeRange: ofTrack: atTime: error: from AVMutableCompositionTrack a second time

First of all, I have to say that I like this forum, it has helped me so much time. I have a problem and I could not find the answer anywhere, so this is my first question.

My problem is this:

I have a video presented by AVPlayerItem, the user can edit the start time of the video using the cutBefore button, which cuts the video to the left of the slider.

The method responsible for cutting the video is as follows:

- (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 you run the - (void)cutBefore for the first time, it works fine when I run it a second time (the video has already been edited once)

 [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

returned with the following error:

The operation could not be completed. (OSStatus error -12780.)

I tried to find the error code but did not find anything.

thanks for the help

+6
source share
4 answers

I have found a workaround to this problem. It seems that using the insertTimeRange:ofTrack:atTime:error: method with the AVMutableComposition track as the input track is causing an error, so I made saving the original asset (which was not an AVMutableComposition instance, but an AVAsset instance) and using its track as input to insertTimeRange:ofTrack:atTime:error:

0
source

I also ran into this problem and solved it by creating a mutable copy of the composition and then deleting the first part of the composition.

 AVMutableComposition *newShortComposition = [oldComposition mutableCopy]; [newShortComposition removeTimeRange:CMTimeRangeMake(kCMTimeZero, <your clip time>)]; 
0
source

I ran into this problem and the problem was in my calculation for the timeRange and startTime this method. timeRange.start.value and startTime.value must be positive. Maybe my late answer will help someone.

0
source

I ran into the same problem and decided that the elk answer above would help you.

"OSStatus error - 12780, operation could not be completed" may occur due to lack of memory from the application, because I did not encounter a problem when running my application on the simulator.

In my case, the error was reproduced when I created several instances of AVAssetTrack before they were inserted into AVMutableCompositionTracks. I changed that only an instance of AVAssetTrack is created immediately before it is inserted into AVMutableCompositionTrack, and then I enabled it.

0
source

Source: https://habr.com/ru/post/887801/


All Articles