AVAssetExportSession导出视频 AVFoundationErrorDomain Code=-11841 错误解决办法
注意合成视频时一定要先添加视频再添加音频否则在合成视频时如果使用非AVAssetExportPresetPassthrough则会报-11841错误,另外如果使用AVAssetExportPresetPassthrough避开-11841错误
在生成后的视频再次使用AVAssetExportSession导出视频时同样会报-11841错误。
在使用AVAssetExportSession合并音视频时一定是先添加视频再添加音频。
the error is Error Domain=AVFoundationErrorDomain Code=-11841 "Operation Stopped" UserInfo={NSLocalizedDescription=Operation Stopped, NSLocalizedFailureReason=The video could not be composed.}
the error is Error Domain=AVFoundationErrorDomain Code=-11841 "操作停止" UserInfo={NSLocalizedDescription=操作停止, NSLocalizedFailureReason=未能创作视频。}
the status is 4
the outPutPath is file:///var/mobile/Containers/Data/Application/37E2EC0B-FCE1-43C5-827E-AFDB4C3948D4/Library/Caches/CroppedVideo.mp4
the error is {
NSLocalizedDescription = "\U64cd\U4f5c\U505c\U6b62";
NSLocalizedFailureReason = "\U672a\U80fd\U521b\U4f5c\U89c6\U9891\U3002";
}
the error is Error Domain=AVFoundationErrorDomain Code=-11841 "操作停止" UserInfo={NSLocalizedDescription=操作停止, NSLocalizedFailureReason=未能创作视频。}
-11841 先添加音频再添加视频报-11841
AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
NSError *error = nil;
AVMutableCompositionTrack *audioCompositionTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
error = nil;
[audioCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, movieURLAsset.duration) ofTrack:audioAssetTrack atTime:kCMTimeZero error:&error];
if (error) {
NSLog(@"error is %@", error);
}
AVMutableCompositionTrack *videoCompositionTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[videoCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, movieURLAsset.duration) ofTrack:videoAssetTrack atTime:kCMTimeZero error:&error];
if (error) {
NSLog(@"error is %@", error);
}
先添加视频再添加音频 不会报错
AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
NSError *error = nil;
AVMutableCompositionTrack *videoCompositionTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[videoCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, movieURLAsset.duration) ofTrack:videoAssetTrack atTime:kCMTimeZero error:&error];
if (error) {
NSLog(@"error is %@", error);
}
AVMutableCompositionTrack *audioCompositionTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
error = nil;
[audioCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, movieURLAsset.duration) ofTrack:audioAssetTrack atTime:kCMTimeZero error:&error];
if (error) {
NSLog(@"error is %@", error);
}
注意合成视频时一定要先添加视频再添加音频否则在合成视频时如果使用非AVAssetExportPresetPassthrough则会报-11841错误,另外如果使用AVAssetExportPresetPassthrough避开-11841错误
在生成后的视频再次使用AVAssetExportSession导出视频时同样会报-11841错误。
综上 在使用AVAssetExportSession合并音视频时一定是先添加视频再添加音频。