In the default photos app, Apple allows you to share videos to youtube, facebook,vimeo, etc.. I want to reproduce this function, but I record my videos in 1080p, so they are very large files. Apple solves this problem by compressing the video before uploading. I tried doing the same but failed miserably. Can anyone point me in the right direction? I found this question useful, but I can't understand why it doesn't work for me: iPhone:Programmatically compressing recorded video to share?.
Here is what I am trying:
- (void)convertVideoToLowQualityWithInputURL:(NSURL *)inputURL
                                   outputURL:(NSURL *)outputURL
                                     handler:(void (^)(AVAssetExportSession *))handler {
    [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
    exportSession.outputURL = outputURL;
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;
    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        switch ([exportSession status]) {
            case AVAssetExportSessionStatusFailed:
                NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
                break;
            case AVAssetExportSessionStatusCancelled:
                NSLog(@"Export canceled");
                break;
            default:
                break;
        }
    }];
}
-someMethod{
    NSURL *videoURL = [NSURL fileURLWithPath:self.currentVideoURL];
    NSArray *videoSplit = [[NSString stringWithFormat:@"%@",videoURL] componentsSeparatedByString: @"."];
    NSString *first = [videoSplit firstObject];
    NSString *output = [NSString stringWithFormat:@"%@_Low_Qual.%@",first,[videoSplit objectAtIndex:1]];
    NSLog(@"VIDEO URL IS: %@",videoURL);
    NSLog(@"OUTPUT URL IS: %@",output);
    NSURL *outputURL = [NSURL fileURLWithPath:output];
    [self convertVideoToLowQualityWithInputURL:videoURL outputURL:outputURL handler: ^(AVAssetExportSession *exportSession)
     {
         if (exportSession.status == AVAssetExportSessionStatusCompleted) {
             printf("completed\n");
         }
         else {
             printf("error\n");
         }
     }];
}
However, it gives me 'Export failed: The operation could not be completed' every time. The video URL's are valid, so I don't know why it won't work. Any ideas?