如何解决iOS 14 从 iCloud 共享相册导出视频到 mp4 失败
作为开发人员,我想将 iCloud 共享相册中的视频导出到 mp4,以便我可以在我的 Messenger 应用中发送视频。
实际上,以下 exportAsynchronouslyWithCompletionHandler 方法总是失败并给出 AVAssetExportSessionStatusFailed 。
常规方法 requestExportSessionForVideo 和 requestAVAssetForVideo 都呈现相同的错误。请告诉我们处理和解决这个困难的方法。
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.networkAccessAllowed = YES;
options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
options.version = PHVideoRequestOptionsversionCurrent;
[[PHImageManager defaultManager] requestExportSessionForVideo:asset options:options exportPreset:AVAssetExportPresetHighestQuality resultHandler:^(AVAssetExportSession * _Nullable exportSession,NSDictionary * _Nullable info) {
if (exportSession && [exportSession.asset isKindOfClass:[AVURLAsset class]]) {
AVAssetTrack *videoTrack = nil;
NSArray *videoTracks = [exportSession.asset tracksWithMediaType:AVMediaTypeVideo];
videoTrack = videoTracks.firstObject;
__block CGSize videoSize = CGSizeApplyAffineTransform(videoTrack.naturalSize,videoTrack.preferredTransform);
__block CMTime duration = exportSession.asset.duration;
NSMutableDictionary *videoInfo = [[UIImage saveVideoInDocumentDirectory] mutablecopy];
[videoInfo re_setobject:caption forKey:kInfoKeyMediaCaption];
[videoInfo re_setobject:[@(fabs(videoSize.width)) stringValue] forKey:kInfoKeyMediawidth];
[videoInfo re_setobject:[@(fabs(videoSize.height)) stringValue] forKey:kInfoKeyMediaHeight];
[videoInfo re_setobject:[Nsstring cmTimeString:duration]forKey:kInfoKeyMediaDuration];
if (result) {
Nsstring *placeholder = [result base64String:0.5];
[videoInfo re_setobject:placeholder forKey:kInfoKeyMediaPreviewBase64];
}
Nsstring *filename = videoInfo[kInfoKeyMediaFileName];
NSURL * _Nullable optionalPath = [NSFileManager fullFileURL:filename];
if (optionalPath) {
NSURL * movieURL = [optionalPath URLByAppendingPathExtension:@"mp4"];
exportSession.videoComposition = nil;
exportSession.outputURL = movieURL;
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.shouldOptimizeforNetworkUse = YES;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void){
switch (exportSession.status) {
case AVAssetExportSessionStatusCompleted:{
addInfo(videoInfo);
break;
}
case AVAssetExportSessionStatusFailed:{
dispatch_async(dispatch_get_main_queue(),^{
[weakSelf re_hideLoadingHUD];
[weakSelf re_show:CommonLocalizableObjC.error_message__please_try_again_later];
});
break;
}
default:
break;
}
}];
}
else {
return;
}
}
else {
errorInfo();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。