特定视频出现 AVAssetExportSession 未知错误 -12780。

19

我在资产导出会话失败的背后问题上遇到了困难。这个问题只出现在一个视频中,我认为问题出在它的音轨上,因为我已经成功地导出了没有音轨(只有视频轨道)的资产。

视频轨道使用AVAssetReader解码,并在被重写成新的视频轨道之前进行样本缓冲区处理;音轨则不经过解码或任何中间处理直接传递。然而,即使没有处理视频样本缓冲区,仍然出现了相同的故障。

我还尝试了另一种方式——只使用音频而没有视频轨道——其他视频正常工作,但是这个特定的视频失败了。我想这个视频的音轨本身存在问题,但我无法推断出问题所在,因此无法解决。以下是我的代码:

AVAssetExportSession* assetExport = [[AVAssetExportSession alloc] initWithAsset:composition
                                                                      presetName:AVAssetExportPresetHighestQuality];

assetExport.outputFileType = @"com.apple.quicktime-movie";
assetExport.outputURL = [NSURL fileURLWithPath:path];

__weak typeof(self) weakSelf = self;
[assetExport exportAsynchronouslyWithCompletionHandler:^{

    switch (assetExport.status) {
        case AVAssetExportSessionStatusCompleted: NSLog(@"Asset combined");
            break;
        case AVAssetExportSessionStatusFailed: NSLog(@"Asset combination failed");
            break;
        default: NSLog(@"Asset combination completed with unknown status: %@", @(assetExport.status));
            break;
    }
}];

问题应该出现在资产导出会话中。向AVMutableComposition插入轨道的操作运行良好。以下是AVAssetExportSession的错误消息:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"
UserInfo={NSUnderlyingError=0x6040001338d0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}, 
NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed}

这个问题解决了吗? - Payal Maniyar
你解决了这个问题吗? - Mohd Haider
虽然已经有一段时间了,但我仍建议接受Fistman的解决方案。至少对我来说是有效的。 - TheLivingForce
@PayalManiyar 你有找到任何解决方案吗? 我遇到了同样的问题。 我的代码之前运行得很完美,但是后来突然停止工作了。我没有在代码中做任何更改。 大家帮帮忙。 - Ankur Patel
3个回答

8

我知道这是一个老问题,但由于它还没有得到解决,我将提供错误代码12780的解决方案。

大多数情况下,问题出在输出URL上。 确保URL像这样创建:

URL(fileURLWithPath: "")

例如:

let temp_output = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("temp_exported.mov")

1
就是这样!我正在使用URL(string: "")。谢谢! - jervine10
1
这是正确的答案。应该使用URL(fileURLWithPath:)而不是URL(string:)。谢谢! - Seyed Samad Gholamzadeh

4

我花了大约两天的时间解决这个问题...... 我没有找出根本原因,但是我发现将audioMix设置为AVAssetExportSession可行。

AVMutableAudioMix *videoAudioMixTools = [AVMutableAudioMix audioMix];
AVMutableAudioMixInputParameters *firstAudioParam = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:assetAudioTrack];
[firstAudioParam setVolumeRampFromStartVolume:1.0 toEndVolume:1.0 timeRange:CMTimeRangeMake(kCMTimeZero, CMTimeSubtract(endCropTime, startCropTime))];
[firstAudioParam setTrackID:compositionAudioTrack.trackID];
videoAudioMixTools.inputParameters = [NSArray arrayWithObject:firstAudioParam];

exportSession.audioMix = videoAudioMixTools;

看起来这会强制解码和重新编码音轨。


1
到了2019年,我终于解决了这个问题!还要注意的是,为了使此解决方案起作用,presetName需要是exportPresetsCompatibleWithAsset中可用的预设之一(例如AVAssetExportPresetHighestQuality),而不是AVAssetExportPresetPassthrough - Cœur

4
猜测:音频轨道与其所属的AVAsset分离,然后该资源超出了范围。尝试在调用exportAsynchronouslyWithCompletionHandler之前保留对音频轨道所属的AVAsset的引用。

天啊……浪费了5个小时,结果答案就是这个。谢谢! - mojuba

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接