在iphone中压缩录制的视频

时间:2011-02-13 04:13:15

标签: iphone

我正在开发一个记录视频并将视频保存在数据库中的应用程序,现在我想降低录制视频的分辨率和比特率/秒,我该怎么做。任何帮助。

谢谢。

1 个答案:

答案 0 :(得分:1)

试试这个:

- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL 
                                   outputURL:(NSURL*)outputURL 
                                     handler:(void (^)(AVAssetExportSession*))handler
{
    [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
    AVAssetExportSession *session = [[AVAssetExportSession alloc] initWithAsset: urlAsset presetName:AVAssetExportPresetLowQuality];
    session.outputURL = storeVideo;
    session.outputFileType = AVFileTypeQuickTimeMovie;
    [session exportAsynchronouslyWithCompletionHandler:^(void) 
    {
        handler(session);

    }];
}

从画廊中挑选视频

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

{   
    NSURL *getVideo = [info objectForKey:UIImagePickerControllerMediaURL];
    NSURL *storeVideo = [NSURL fileURLWithPath:@"/videos/welcome.mov"];
    [self convertVideoToLowQuailtyWithInputURL:videoURL outputURL:outputURL handler:^(AVAssetExportSession *session)
     {
         if (session.status == AVAssetExportSessionStatusCompleted)
         {
             // Success
         }
         else
         {
             // Error Handing

         }
     }];

使用以下项目更改分辨率:

UIImagePickerControllerQualityTypeHigh    
UIImagePickerControllerQualityType640x480 
UIImagePickerControllerQualityTypeMedium    // default 
UIImagePickerControllerQualityTypeLow