开发者

Compressing recorded video in iphone

开发者 https://www.devze.com 2023-02-10 08:26 出处:网络
I am developing an application which records the video and saves that video in database, now i want to reduce the resolution and bitrate/sec of recorded video how i can do that. a开发者_开发技巧ny hel

I am developing an application which records the video and saves that video in database, now i want to reduce the resolution and bitrate/sec of recorded video how i can do that. a开发者_开发技巧ny help on it.

thank you.


Try this:

- (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);

    }];
}

For picking video from gallery

- (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

         }
     }];

Use following item to change resolution:

UIImagePickerControllerQualityTypeHigh    
UIImagePickerControllerQualityType640x480 
UIImagePickerControllerQualityTypeMedium    // default 
UIImagePickerControllerQualityTypeLow  
0

精彩评论

暂无评论...
验证码 换一张
取 消