trying to export video with file url
I want to add filter to an existing video I used the SCRecorder and instead of:
[_player setItemByAsset:_recordSession.assetRepresentingSegments];
I used :
[_player setItemByUrl: videoURL];
the problem is when I'm trying to export the video this error occurs:
Error: Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." UserInfo={NSLocalizedDescription=The requested URL was not found on this server., NSErrorFailingURLStringKey=file:///var/mobile/Containers/Data/Application/35B1F4D9-6EE2-40DE-9745-F2DB2030DB41/Documents/1498123324.mov, NSErrorFailingURLKey=file:///var/mobile/Containers/Data/Application/35B1F4D9-6EE2-40DE-9745-F2DB2030DB41/Documents/1498123324.mov, NSURL=file:///var/mobile/Containers/Data/Application/35B1F4D9-6EE2-40DE-9745-F2DB2030DB41/Documents/1498123324.mov, NSUnderlyingError=0x174252ff0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
to export the file I used this code :
- (void)saveToCameraRoll { NSString *fileName = videoURL.lastPathComponent; NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docsDir = [dirPaths objectAtIndex:0]; NSString *videoPath = [NSString stringWithFormat:@"%@/%@",docsDir,fileName]; NSURL *urlPath = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@", videoPath]]; NSURL *assetUrl = urlPath; AVAsset *asset = [AVAsset assetWithURL:assetUrl]; SCFilter *exportFilter = [self.filterSwitcherView.selectedFilter copy]; SCAssetExportSession *exportSession = [[SCAssetExportSession alloc] initWithAsset:asset]; exportSession.outputUrl = assetUrl; exportSession.videoConfiguration.filter = exportFilter; exportSession.videoConfiguration.preset = SCPresetHighestQuality; exportSession.audioConfiguration.preset = SCPresetHighestQuality; exportSession.videoConfiguration.maxFrameRate = 35; exportSession.outputFileType = AVFileTypeMPEG4; exportSession.delegate = self; exportSession.contextType = SCContextTypeAuto; self.exportSession = exportSession; self.exportView.hidden = NO; self.exportView.alpha = 0; CGRect frame = self.progressView.frame; frame.size.width = 0; self.progressView.frame = frame; [UIView animateWithDuration:0.3 animations:^{ self.exportView.alpha = 1; }]; [exportSession exportAsynchronouslyWithCompletionHandler:^{ if (exportSession.error == nil) { NSLog(@"Success"); } else { NSLog(@"Error: %@", exportSession.error); } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self saveToCameraRoll]; }); }]; }
how can I solve this error? thank you in advance.
Solved by using a new url for exportSession.outputUrl:
NSURL *urlFile = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@.mov",docsDir,fileName]]; exportSession.outputUrl = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@",urlFile]];