Shiva Reddy
Shiva Reddy

Reputation: 456

Compressing recorded video in iphone

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. any help on it.

thank you.

Upvotes: 0

Views: 1297

Answers (1)

Rajesh Loganathan
Rajesh Loganathan

Reputation: 11217

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  

Upvotes: 1

Related Questions