出于某种原因,我总是收到此错误:
错误域= NSURLErrorDomain代码= -3000“无法创建文件” UserInfo = {NSLocalizedDescription =无法创建文件, NSUnderlyingError = 0x1321dd730 {错误域= NSOSStatusErrorDomain 代码= -12115“(null)”}}
尝试将AVSession导出到m4a时。这在我的同事设备上运行良好,但每次在我的iPad Air 2(iOS 9.1)以及我们的QA iPad Mini 3上都会失败。
- (void)processSourceVideoFile:(NSURL *)mediaURL completion:(void (^)(BOOL success))completion {
[self showProgressOverlay];
NSString *outputFileType = AVFileTypeMPEG4;
__block NSString *videoID = nil;
if (self.videoAttachment == nil) {
[MagicalRecord saveUsingEditContextWithBlockAndWait:^(NSManagedObjectContext *localContext) {
self.videoAttachment = [SPXAttachment MR_createEntityInContext:localContext];
self.videoAttachment.uuid = [NSString uuid];
self.videoAttachment.clientCreatedAt = [NSDate date];
videoID = self.videoAttachment.uuid;
}];
} else {
videoID = self.videoAttachment.uuid;
}
self.videoAttachment = [SPXAttachment MR_findFirstByAttribute:@"uuid" withValue:videoID];
NSString *targetPath = self.videoAttachment.filePath;
DDLogVerbose(@"Exporting Video to %@", targetPath);
if ([[NSFileManager defaultManager] fileExistsAtPath:targetPath]) {
[[NSFileManager defaultManager] removeItemAtPath:targetPath error:nil];
}
AVAsset *video = [AVAsset assetWithURL:mediaURL];
self.exportSession = [AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPreset640x480];
self.exportSession.outputFileType = outputFileType;
self.exportSession.outputURL = [NSURL fileURLWithPath:targetPath];
[self.exportSession exportAsynchronouslyWithCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self hideProgressOverlay];
});
switch (self.exportSession.status) {
case AVAssetExportSessionStatusFailed:
DDLogError(@"Video Export Failed: %@", self.exportSession.error);
completion(NO);
break;
case AVAssetExportSessionStatusCancelled:
DDLogVerbose(@"Video Export Cancelled");
break;
case AVAssetExportSessionStatusCompleted: {
DDLogVerbose(@"Video Export Complete for %@", targetPath);
BOOL dir;
if ([[NSFileManager defaultManager] fileExistsAtPath:targetPath isDirectory:&dir]) {
DDLogVerbose(@"FILE IS THERE MOFO!!");
}
completion(YES);
}
break;
default:
break;
}
}];
}
来源网址:file:///private/var/mobile/Containers/Data/Application/BD85BA54-5B3D-4533-A142-C2A30F373814/tmp/capture-T0x12fe1e8e0.tmp.CbksL4/capturedvideo.MOV
输出网址:file:/// var / mobile / Containers / Data / Application / BD85BA54-5B3D-4533-A142-C2A30F373814 / Library / Files / 59124681-ba1a-4453-8078-9ca6ac3088bf / attachments / 454dd782-6b14 -44cd-9f4e-84664908388b
我尝试将文件扩展名(.mp4)添加到输出网址,但没有帮助。我搜索过的东西与这个场景完全匹配。
任何帮助表示赞赏!
答案 0 :(得分:0)
确保输出网址的路径末尾有.mp4文件扩展名。
答案 1 :(得分:0)
文件名中的日期可能带有正斜杠。 在AVAssetExportSession中,目录名而不是文件名可以使用正斜杠。