开发者

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

开发者 https://www.devze.com 2023-03-04 05:53 出处:网络
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.

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


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.


I found a workaround to this issue, It seems that using the method insertTimeRange:ofTrack:atTime:error: with AVMutableComposition's track as the input track causing the error, so what I did was saving the initial asset (which wasn't an instance of AVMutableComposition but an instance of AVAsset), and using it track as an input to insertTimeRange:ofTrack:atTime:error:


I also came across this problem and solved it by creating a mutable copy of the composition and then removing the first part of the composition.

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


I encountered the same problem and resolved, elk's answer above will help you.

"OSStatus error - 12780, The operation couldn't be completed" might occur by lack of memory out of app because I had not come across the problem when I ran my app on a simulator.

In my case, the error was reproduced when I created multiple AVAssetTrack instances before they were inserted in AVMutableCompositionTracks. I changed that only a AVAssetTrack instance is created just before it's inserted in the AVMutableCompositionTrack and then I resolved it.


if the audio's duration is CMTime.zero, insertTimeRange will throw a exception

if audioAsset.duration == CMTime.zero {
    return
}
0

精彩评论

暂无评论...
验证码 换一张
取 消