ios - AVAssetExportSession 无法创建文件错误-12115

标签 ios avfoundation avassetexportsession m4a avasset

出于某种原因,我总是收到此错误:

Error Domain=NSURLErrorDomain Code=-3000 "Cannot create file" UserInfo={NSLocalizedDescription=Cannot create file, NSUnderlyingError=0x1321dd730 {Error Domain=NSOSStatusErrorDomain Code=-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

我尝试向输出 URL 添加文件扩展名 (.mp4),但没有帮助。我四处搜索,没有什么能与这种情况完全匹配。

感谢任何帮助!

最佳答案

确保您的输出 URL 的路径末尾有 .mp4 文件扩展名。

关于ios - AVAssetExportSession 无法创建文件错误-12115,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33925066/

相关文章:

ios - Ionic2 iOS 转换阻止点击或点击一秒钟

macos - NSFileManager 说文件不可写 Mac

ios - AVAssetExportSession 不遵守视频合成说明

ios - 如何导出任意一段视频?导出最后 X 秒视频时出现 "Operation Stopped"错误

ios - Trigger.io iOS 插件从回调返回数据

ios - SpriteKit : How to prevent two SKSpriteNodes from colliding (in Swift)

ios6 - AVAssetWriter finishWritingWithCompletionHandler 错误与未知错误

php readFile() 和移动 safari

android - 如何开始Android/iOS配件开发?

ios - 如何使用 vImageMatrixMultiply 将 YUV 平面数据转换为 32 bpp、8bpc RGBX?