OSStatus 错误 - 第二次调用 AVMutableCompositionTrack 的 insertTimeRange:ofTrack:atTime:error: 时出现 12780
首先我必须说我喜欢这个论坛,它帮助了我很多次。 我有一个问题,但在任何地方都找不到答案,所以这是我的第一个问题。
我的问题是这样的:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我遇到了这个问题,问题出在我对此方法的
timeRange
和startTime
参数的计算上。timeRange.start.value
和startTime.value
必须为正数。也许我迟来的回答会对某人有所帮助。I faced with this issue and problem was with my calculation for
timeRange
andstartTime
parameters of this method.timeRange.start.value
andstartTime.value
must be positive. Maybe my late answer will help someone.我找到了解决此问题的方法,似乎使用方法
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 toinsertTimeRange: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.
我遇到了同样的问题并解决了,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.
如果音频的持续时间是 CMTime.zero,insertTimeRange 将抛出异常
if the audio's duration is CMTime.zero, insertTimeRange will throw a exception