Error -11800 when attempting to insertTimeRange of AVComposition to AVMutableComposition
Asked Answered
P

3

7

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?

Policlinic answered 5/3, 2014 at 23:2 Comment(3)
I've just tried using a for loop and objectAtIndex: instead of fast enumeration over the self.segments NSMutableArray and it's no different.Policlinic
Did you ever figure it out? I am running into a very similar issues (with video however, not just audio - error numbers are also slightly different AVFoundationErrorDomain Code=-11801, and (OSStatus error -12786.))Tuttle
try to use :fileURLWithPath instead of :urlwithstringSchurman
T
2

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
Theirs answered 15/1, 2021 at 16:26 Comment(0)
D
1

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];
Doublereed answered 26/10, 2015 at 6:5 Comment(0)
M
-1

Make sure segment.asset is not released. So if the condition segment.asset == nil is true, the media data behind is gone, so the insert action failed.

ref: https://www.jianshu.com/p/089f6691dbdb (at bottom of the article)

Mismanage answered 16/3, 2018 at 1:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.