录制高清视频,保存低质量视频

时间:2013-12-14 23:12:21

标签: ios objective-c cocoa-touch core-data uiimagepickercontroller

我目前正在使用UIImagePickerController录制视频并保存。我使用1080p质量,因此短视频仍然很大。在我的应用中,用户可以通过电子邮件发送他们录制的视频,因此拥有大型视频并不合适。有什么方法可以保存2个版本的视频(高质量和低质量),一个保存在〜/ app-folder / video-name.mov,然后另一个保存在〜/ app-folder / video-name-SD .mov格式?或者保存高清视频,但不知何故有SD版本?欢迎所有解决方案,而不仅仅是保存SD版本。这就是我正在做的事情:

  - (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];
}

1 个答案:

答案 0 :(得分:0)

首先以高质量录制视频,然后使用AVAssetWriter或AVAssetExportSession制作质量较低的副本,如下所述:

iPhone:Programmatically compressing recorded video to share?