I have implemented an overlay view when calling camera view before recording the video.
pickerController.cameraOverlayView =myOverlay;
Video recording and saving the video into Album after recording the video and sharing via email etc. all works fine.
If i use video quality as "High quality", then the recorded video has become huge size. For example, if i record video for 30 seconds with high quality, recorded video has become around 30 - 40 mb.
pickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
How do i program to compress the high quality recorded video before sharing it, like how Apple does with built-in Video recorder?
Please guide me to resolve this.
Thanks!
UPDATED:
This is what i'm trying recently, but still no success: I want to compress the recorded video taken which comes to didFinishPickingMediaWithInfo and store in same photo album actual video path itself, not anywhere else. I tested the same video is compressed to very small size when i pick from photo library, but the same video taken from camera and came via didFinishPickingMediaWithInfo is not compressed, though i used the AVAssetExportSession code below.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSString *urlPath = [videoURL path];
if ([[urlPath lastPathComponent] isEqualToString:@"capturedvideo.MOV"])
{
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (urlPath))
{
[self copyTempVideoToMediaLibrary :urlPath];
}
else
{
NSLog(@"Video Capture Error: Captured video cannot be saved...didFinishPickingMediaWithInfo()");
}
}
else
{
NSLog(@"Processing soon to saved photos album...else loop of lastPathComponent..didFinishPickingMediaWithInfo()");
}
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)copyTempVideoToMediaLibrary :(NSString *)videoURL {
dispatch_queue_t mainQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(mainQueue, ^{
ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
ALAssetsLibraryWriteVideoCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) {
NSLog(@"Saved URL: %@", assetURL);
NSLog(@"Error: %@", error);
if (assetURL != nil) {
AVURLAsset *theAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:videoURL] options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:theAsset];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:theAsset presetName:AVAssetExportPresetLowQuality];
[exportSession setOutputURL:[NSURL URLWithString:videoURL]];
[exportSession setOutputFileType:AVFileTypeQuickTimeMovie];
[exportSession exportAsynchronouslyWithCompletionHandler:^ {
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(@"Export session faied with error: %@", [exportSession error]);
break;
default:
//[self mediaIsReady];
break;
}
}];
}
};
[library writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:videoURL] completionBlock:completionBlock];
});
}
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…