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

Posted

技术标签:

【中文标题】录制高清视频,保存低质量视频【英文标题】:Record HD video, save low quality video 【发布时间】:2013-12-14 23:12:20 【问题描述】:

我目前正在使用 UIImagePickerController 录制视频并保存。我使用的是 1080p 质量,所以短视频仍然可以很大。在我的应用程序中,用户可以通过电子邮件发送他们录制的视频,因此拥有大视频是不行的。有什么办法可以保存 2 个版本的视频(高质量和低质量),一个保存在 ~/app-folder/video-name.mov,另一个保存在 ~/app-folder/video-name-SD .mov?或者以某种方式保存高清视频但有一个标清版本?欢迎所有解决方案,而不仅仅是保存 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】:

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

iPhone:Programmatically compressing recorded video to share?

【讨论】:

以上是关于录制高清视频,保存低质量视频的主要内容,如果未能解决你的问题,请参考以下文章

从技术全景到场景实战,透析「窄带高清」的演进突破

从技术全景到场景实战,透析「窄带高清」的演进突破

人人都会用的视频录制软件,让你轻松录制高清视频~

用ffmpeg录制小程序直播开发高清视频并实现直播推流

Bandicam(班迪录屏)高清视频录制工具

录制高清视频最好用的屏幕录像软件