I am attempting to trim a video using the following code:
AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@.mp4",documentsDirectory,name]] options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:videoAsset presetName:AVAssetExportPresetHighestQuality];
NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@/finalOutput.mp4",documentsDirectory]];
exportSession.outputURL = url;
NSLog(@"outputting to: %@", [NSString stringWithFormat:@"%@/finalOutput.mp4",documentsDirectory,name]);
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTimeRange timeRange = CMTimeRangeMake(flashbackStart, CMTimeSubtract(flashbackEnd, flashbackStart));
exportSession.timeRange = timeRange;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch (exportSession.status) {
case AVAssetExportSessionStatusCompleted:
// Custom method to import the Exported Video
//[self loadAssetFromFile:exportSession.outputURL];
NSLog(@"completed!!!");
break;
case AVAssetExportSessionStatusFailed:
//
NSLog(@"Failed:%@",exportSession.error);
break;
case AVAssetExportSessionStatusCancelled:
//
NSLog(@"Canceled:%@",exportSession.error);
break;
default:
break;
}
}];
However, I’m getting a bad access error for this line:
[exportSession exportAsynchronouslyWithCompletionHandler:^{
Even with NSZombie enabled, I’m not getting any details about the error. Can anyone explain what’s going on here? The input video file does exist, and the output video file does not exist before I attempt to write to it.
Thanks,
James
It turns out the problem was with the
NSURLs I used. All I had to do was useinitFileURLWithPathand the problem was solved!