AVAssetExportSession "cannot create file"

MacOS. I have a translator for .mov to .mp4, but get the "cannot create file" failure message. It passes the compatibility check. Is there some kind of a sandbox issue here.


NSURL *srcURL = [NSURL fileURLWithPath:self.srcPath]; // ".mov"

NSURL *destURL = [NSURL fileURLWithPath:self.destPath]; // Same as above, but ".mp4"


AVAsset *avAsset = [AVURLAsset URLAssetWithURL:srcURL options:nil];


self.exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];

self.exportSession.outputURL = destURL;

self.exportSession.outputFileType = AVFileTypeMPEG4;

[self.exportSession exportAsynchronouslyWithCompletionHandler:^{

switch (self.exportSession.status) {

case AVAssetExportSessionStatusFailed:

NSLog(@"Export failed: %@", [[self.exportSession error] localizedDescription]);

break;

case AVAssetExportSessionStatusCancelled:

NSLog(@"Export canceled.");

break;

case AVAssetExportSessionStatusCompleted:

NSLog(@"Export completed.");

break;

case AVAssetExportSessionStatusExporting:

self.progress = self.exportSession.progress;

break;

default:

break;

}

}];

Replies

Apparently, sandboxing it is. Normally, I use a button to set destination path to same as source path, except with ".mp4". I have another button to use the Save Panel to set destination path. The latter works. Looks like I have to find out how to temporarily break sandboxing, (Seems like I've done that elsewhere before.) I don't think I had to do this for AVCaptureMovieFileOutput, so why here?


Not having much luck googling this. With AVCaptureMovieFileOutput, I programmatically determine the file URL and call

startRecordingToOutputFileURL:... and it works. Seems to me that it is an ovesight that AVAssetExportSession has a sandbox issue. Should I file a bug report? Regardless, what is the best way to fix this for now?

Ok, now I'm thououghly ticked off. What started as a simple utility project (using the above code) has now turned into a nightmare, due to sandboxing. While I might be able to live with manually setting the output using an (inconvenient) Save Panel, we also desired to make this an automatic option, not requiring the user to do anything to make it happen. Noooooo way, Jose! Looks like we are going to have to, at the very least, deal with coordinated writing (a PITA). I don't understnd any of this stuff, but have figured out that the documented File Access Temporary Exceptions are totally useless unless you always want to write to one location.


I did find "OSX App Sandboxing & Related Items tutorial" which is written in outdated Swift which I will have to translate into Objective C. If I can figure out exactly what it is doing, I might be able to use that. However, it appears that you have to add document types that the app really cant open, and besides, our conversion utility is a singleton at the application level.


This is all utterly ridiculous. There has to be a better way. If the PowerBox can figure out it's ok to access a particular location, why can't we just give it a URL and let it figure out if it's ok? Huh? Huh? Get with it out there in the new Space Port, how about it!


Later:

I tried doing this using related items with a file coordinator. So far, no luck.


- (void) convertWithCoordinator {

self.fileData = [FileData fileDataWithPath:self.srcPath];

[NSFileCoordinator removeFilePresenter:self.fileData];

[NSFileCoordinator addFilePresenter:self.fileData];

FileData *fData = self.fileData;

NSURL *url = fData.presentedItemURL;

NSError *error;

__block BOOL failure = YES;

NSFileCoordinator *coord = [[NSFileCoordinator alloc] initWithFilePresenter:fData];

[coord coordinateWritingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL){

[self convertMOVToMP4AtURL:newURL];

failure = NO;

}];


if(failure || error != nil)

NSLog(@"%@", error.description);

}


fileData conforms to NSFilePresenter. Requisite info is included in info.plist. No failure occurs here. convertMOVToMP4AtURL is the same as used when the SavePanel is used (successfully). Running it gets "cannot create file". Obviously, "newURL" is NOT the security scoped URL that I need. Why not?

I've had some success. Before recording a captured movie, the user has to select the folder to write to. I automatically append numerical sufixes when needed to prevent overwrites. The URL is also saved as a secure bookmark. No problem (optionally) automatically creating a MPEG4 file immediately after record completion. I can also convert files if the user selects source and destination with panels. However, I still cannot get the "related items" thing to work where only one panel access would be needed.


Filed Bug Report: 30638999 Related Items Failing in NSFileCoordinator

Did anyone ever get an answer to this? I had similar code working fine in a released app but as I updated to Swift 3.0 I keep getting "Cannot create file". Not sure what I am doing wrong?