OSStatus 错误 - 第二次调用 AVMutableCompositionTrack 的 insertTimeRange:ofTrack:atTime:error: 时出现 12780

发布于 2024-11-06 05:47:12 字数 2616 浏览 6 评论 0原文

首先我必须说我喜欢这个论坛,它帮助了我很多次。 我有一个问题,但在任何地方都找不到答案,所以这是我的第一个问题。

我的问题是这样的:

cutBefore 按钮编辑视频开始时间,该按钮将视频剪切到滑块的左侧

视频的方法如下:

- (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];

负责剪切

我有一个由 AVPlayerItem 表示的视频,用户可以使用 - (void)cutBefore 方法第一次工作正常,当我第二次运行它时(视频已经编辑过一次)

[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];

方法返回以下错误:

操作无法完成。 (OSStatus 错误 -12780。)

我试图查找该错误代码的含义,但几乎什么也没找到。

感谢您的帮助

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

菊凝晚露 2024-11-13 05:47:12

我遇到了这个问题,问题出在我对此方法的 timeRangestartTime 参数的计算上。 timeRange.start.valuestartTime.value 必须为正数。也许我迟来的回答会对某人有所帮助。

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.

酒解孤独 2024-11-13 05:47:12

我找到了解决此问题的方法,似乎使用方法 insertTimeRange:ofTrack:atTime:error: 并将 AVMutableComposition 的轨道作为输入轨道导致错误,所以我所做的是保存初始资源(它不是 AVMutableComposition 的实例,而是 AVAsset 的实例),并使用它跟踪作为输入insertTimeRange:ofTrack:atTime:error:

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:

心病无药医 2024-11-13 05:47:12

我也遇到了这个问题,并通过创建组合的可变副本然后删除组合的第一部分来解决它。

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

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>)];
〗斷ホ乔殘χμё〖 2024-11-13 05:47:12

我遇到了同样的问题并解决了,elk上面的回答对你有帮助。

“OSStatus 错误 - 12780,操作无法完成”可能是由于应用程序内存不足而发生,因为当我在模拟器上运行应用程序时没有遇到该问题。

就我而言,当我在将多个 AVAssetTrack 实例插入 AVMutableCompositionTracks 之前创建它们时,会重现该错误。我更改为仅在将 AVAssetTrack 实例插入 AVMutableCompositionTrack 之前创建它,然后我解决了它。

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.

对你再特殊 2024-11-13 05:47:12

如果音频的持续时间是 CMTime.zero,insertTimeRange 将抛出异常

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

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

if audioAsset.duration == CMTime.zero {
    return
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文