Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error -11800 when attempting to insertTimeRange of AVComposition to AVMutableComposition

I'm working with AVFoundation using audio only - i.e. no video - and trying to join several AVCompositions together, one after the other, to end up with one single AVComposition.

Example case: just two AVCompositions. Each of them plays fine by creating an AVPlayer thus:

_player = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWithAsset:comp]]

where comp is an instance of AVMutableComposition. (Incidentally, it's worth noting that _player has to be an ivar otherwise ARC prematurely releases it before it plays - took a while to track that one down.)

That's good - executing

[_player play]

results in comp being played back successfully.

However, this fails:

(self.segments is an NSMutableArray containing elements that are a custom subclass of AVMutableComposition)

AVMutableComposition *comp = [AVMutableComposition composition];
NSError *err;
for (AVMutableComposition* c in self.segments) {
    [comp insertTimeRange:CMTimeRangeMake(kCMTimeZero, segment.duration)      
                  ofAsset:segment atTime:comp.duration error:&err];
    DLog(@"Error was %@", segment, err);
}

For every element of self.segments when this code executes, I get this error when invoking the insertTimeRange:::: method:

Error was Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not
be completed" UserInfo=0x14e8e7f0 {NSLocalizedDescription=The operation could not be 
completed, NSUnderlyingError=0x14d7f580 "The operation couldn’t be completed. (OSStatus 
error -12780.)", NSLocalizedFailureReason=An unknown error occurred (-12780)}

I can't find any information about what this error indicates - seems to be just a catch-all - and I can't see what I'm doing wrong. Any ideas?

like image 428
jf_by_the_sea Avatar asked Mar 05 '14 23:03

jf_by_the_sea


2 Answers

This code error corresponds to AVErrorUnknown = -11800 so there is not much explanation about the cause of the issue. https://developer.apple.com/documentation/avfoundation/averror/averrorunknown?language=objc

Just in case it might help somebody else I'll point out here my reason.

Context

In my case, I was getting the error when trying to connect to Airplay.

Cause

The cause was that I have 2 instances of AVPlayer. One for a movie type video and another one for a preview. Then when I was trying to cast the movie... AVFoundation was getting confused and it was delivering this error.

Solution

On the moviePlayback instance:

allowsExternalPlayback = true
usesExternalPlaybackWhileExternalScreenIsActive = true

On the default instance:

allowsExternalPlayback = false
usesExternalPlaybackWhileExternalScreenIsActive = false
like image 62
TomCobo Avatar answered Nov 19 '22 01:11

TomCobo


In my case, CMTimeRange was wrong and duration == 0. This is because CMTimeMake will convert the input to an integer and it loses precision.

To solve this problem, I used a bigger time scale.

Problem code:

CMTime startTime = CMTimeMake(timeStamp.begin, 1);
CMTime duration = CMTimeMake(timeStamp.duration, 1);

Right code:

CMTime startTime = CMTimeMake(timeStamp.begin*1000, 1000);
CMTime duration = CMTimeMake(timeStamp.duration*1000, 1000);

then it works properly.

[videoTrack insertTimeRange:CMTimeRangeMake(startTime, duration) ofTrack:videoTracks.firstObject atTime:kCMTimeZero error:&error];
like image 26
Feng Avatar answered Nov 18 '22 23:11

Feng