场景:相册视频导出,导出出现下面错误:
Error Domain=AVFoundationErrorDomain Code=-11800 "这项操作无法完成" UserInfo={NSLocalizedFailureReason=发生未知错误(-12769), NSLocalizedDescription=这项操作无法完成, NSUnderlyingError=0x281c65ec0 {Error Domain=NSOSStatusErrorDomain Code=-12769 "(null)"}}
出现此错误,
1)、首先检查传入的输出路径是否有问题;
2)、presetName
是否支持
3)、若其他配置参数都正确,还考虑是否为该视频编码有问题,可能是生成该视频时编码器出现了问题,可以通过下面方式让AVAssetExportSession重新编码来解决
AVMutableComposition *mainComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *compositionVideoTrack = [mainComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
int timeScale = 100000;
Float64 seconds = CMTimeGetSeconds([avAsset duration]) - 0.001;
NSUInteger videoDurationI = (NSUInteger) (seconds * timeScale);
CMTime videoDuration = CMTimeMake(videoDurationI, timeScale);
CMTimeRange videoTimeRange = CMTimeRangeMake(kCMTimeZero, videoDuration);
NSArray<AVAssetTrack *> *videoTracks = [avAsset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *videoTrack = [videoTracks objectAtIndex:0];
[compositionVideoTrack insertTimeRange:videoTimeRange
ofTrack:videoTrack
atTime:kCMTimeZero
error:nil];
AVAssetExportSession *session = [[AVAssetExportSession alloc] initWithAsset:mainComposition presetName:presetName];