AVAssetExportSession Cannot create file Error -12115
Asked Answered
M

2

6

For some reason I am always receiving this error:

Error Domain=NSURLErrorDomain Code=-3000 "Cannot create file" UserInfo={NSLocalizedDescription=Cannot create file, NSUnderlyingError=0x1321dd730 {Error Domain=NSOSStatusErrorDomain Code=-12115 "(null)"}}

when attempting to export an AVSession to m4a. This works fine on my co-workers device, however it fails every time on my iPad Air 2 (iOS 9.1), as well as our 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;
        }
    }];
}

Source URL: file:///private/var/mobile/Containers/Data/Application/BD85BA54-5B3D-4533-A142-C2A30F373814/tmp/capture-T0x12fe1e8e0.tmp.CbksL4/capturedvideo.MOV

Output URL: file:///var/mobile/Containers/Data/Application/BD85BA54-5B3D-4533-A142-C2A30F373814/Library/Files/59124681-ba1a-4453-8078-9ca6ac3088bf/attachments/454dd782-6b14-44cd-9f4e-84664908388b

I tried adding a file extension (.mp4) to the output URL and that did not help. I have searched around nothing quite matches this scenario.

Any help appreciated!

Manner answered 25/11, 2015 at 19:38 Comment(3)
Did you solve this?Neckline
Make sure that your Output URL has the .mp4 file extension.Manner
On a Mac, please make sure you have permissions to write to the file like via (Sandbox may disallow write-access): BOOL isWritable = [[NSFileManager defaultManager] isWritableFileAtPath:outputURL.path]; NSLog(@"is writable: %@",@(isWritable));Isomagnetic
M
1

Make sure that your Output URL's path has the .mp4 file extension at the end.

Manner answered 3/6, 2016 at 17:41 Comment(0)
C
1

You probably have a date in the file name with forward slashes. Forward slashes are fine for a dir name but not a file name in a AVAssetExportSession.

Cedrickceevah answered 19/9, 2018 at 18:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.