0

I'm currently using UIImagePickerController to record a video and save it. I'm using 1080p quality so a short video can still be large. In my app, the user can send the videos they recorded by email, so having a large video isn't ok. Is there any way I can save 2 versions of the video(high quality and low quality), one saved at ~/app-folder/video-name.mov, then the other at ~/app-folder/video-name-SD.mov? Or save the HD video but have an SD version somehow? All solutions are welcome, not just saving an SD version. Here is what i'm doing:

  - (BOOL)startCameraControllerFromViewController:(UIViewController *)controller
                                      usingDelegate:(id)delegate {

//setup for video recording
//imagePickerWithout is a subclass of UIImagePicker

        imagePickerWithout *cameraUI = [[imagePickerWithout alloc] init];
        cameraUI.videoQuality = UIImagePickerControllerQualityTypeHigh;

        [controller presentViewController:cameraUI animated:YES completion:nil];
        return YES;
    }

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

//setup video

        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
        NSData *videoData = [NSData dataWithContentsOfURL:videoURL];

            //pseudocode :(
            NSData *lowQualData = [NSData LOW_QUALITY_VERSION_OF_URL:videoURL];

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        int random = arc4random() % 80085;

        NSString *tempPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@_%d.mov", self.person.first, self.person.last, self.person.age, random]];

NSString *sdPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_%@_%dLOWQUAL.mov", self.person.first, self.person.last, self.person.age, random]];

        NSFileManager *fileManager = [NSFileManager defaultManager];

        BOOL success = [videoData writeToFile:tempPath atomically:YES];
            BOOL success = [lowQualData writeToFile:sdPath atomically:YES];

        NSError *error = nil;
        [_managedObjectContext save:&error]
}
[self dismissViewControllerAnimated:YES completion:nil];
}
Josue Espinosa
  • 5,009
  • 16
  • 47
  • 81

1 Answers1

0

Record the video in high quality first, and then make a lower quality copy using AVAssetWriter or AVAssetExportSession as described here:

iPhone:Programmatically compressing recorded video to share?

Community
  • 1
  • 1
samfr
  • 656
  • 1
  • 6
  • 19