UIImagePickerController: weird video compression result

In my application, the user can either record a video or select it from his library. Naturally, I use UIImagePickerController with it sourceType installed either in UIImagePickerControllerSourceTypeCamera or UIImagePickerControllerSourceTypePhotoLibrary . In both cases, videoQuality is equal to UIImagePickerControllerQualityTypeMedium .

Now I have done the following: I took a 15-second video with my iPhone lying on it, so that it is black and black. When I select this video from the library, it is about 0.6 MB. When I shoot the same video from my application (15 seconds, black and white), I get a file larger than 4 MB.

Can anyone confirm this? I can hardly believe that I am the first to notice, but then again, I don’t have much space to attach it here (which I probably did nonetheless). Or does anyone have an explanation / solution for this?

(I'm on iOS 5.1 with iPhone 4)

+4
source share
3 answers

Do you get it?

Now I have the same problem, the video in PhotoLibrary (2 more minutes); When I get it using the UIImagePickerController, it is about 30 MB; But I get asset.defaultRepresentation (use this method ( Getting video from ALAsset )), it reaches about 300 MB; Perhaps the UIImagePickerController somehow compressed the data; I need to understand this, but not make progress .......

=================

EDIT: UIVideoEditorController can compress video to a small size; and you can set videoQuality in the same way as UIImagePickerController.

it could be this: when you use UIImagePickerController to select a video and set allowEditing = YES, it will present the UIVideoEditorController to compress the video, then you will get a small compressed video.

0
source

I get it now. The solution is not to reduce the size, but in bitrate. That is, I think that Apple does when you select a video from the library.

See my answer here: fooobar.com/questions/104517 / ...

0
source

The best way to compress video.

Here is the code.

  -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; NSData *data = [NSData dataWithContentsOfURL:videoURL]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0]; NSString *caldate = [NSString stringWithFormat:@"%@.mov",[now description]]; caldate = [caldate stringByReplacingOccurrencesOfString:@" " withString:@""]; NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [NSString stringWithFormat:@"%@/%@", documentsDirectory,caldate]; NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; NSURL *selectedVideoUrl; if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) { tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; selectedVideoUrl = [info objectForKey:UIImagePickerControllerMediaURL]; } NSLog(@"old move %@",path); NSURL *url = [NSURL fileURLWithPath:tempFilePath]; [data writeToFile:path atomically:YES]; //Delete the original asset NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory1 = [paths1 objectAtIndex:0]; NSString *path1 = [NSString stringWithFormat:@"%@/%@", documentsDirectory1,caldate]; NSURL *url1 = [NSURL fileURLWithPath:path1]; NSLog(@"new move %@",path); [self convertVideoToLowQuailtyWithInputURL:url outputURL:url1 handler:Nil]; [picker dismissModalViewControllerAnimated: YES]; 

}

  -(void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL handler:(void (^)(AVAssetExportSession*))handler{ AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil]; AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetMediumQuality]; exportSession.outputURL = outputURL; if ([[UIApplication sharedApplication]canOpenURL:inputURL]){ NSLog(@"open"); } exportSession.outputFileType = AVFileTypeQuickTimeMovie; NSLog(@"errrsfseSession %@", exportSession.error); [exportSession exportAsynchronouslyWithCompletionHandler:^(void) { if(exportSession.status != AVAssetExportSessionStatusCompleted){ NSLog(@"exportSession %@", exportSession.error); } if (exportSession.status == AVAssetExportSessionStatusCompleted) { NSLog(@"doneszdfsadj"); } }]; } 
-1
source

All Articles