UIStatusBar become red after using AVAssetExportSession for UIImagePickerController media conversion - ios

I am converting the .MOV video i get from UIImagePickerController to the .mp4 format using AVAssetExportSession. Once the conversion is completed I send the data to a server. Everything works fine, except the status bar become red and pulsing after the transmission is completed. If I put the app in background and open it again, then the status bar returns to its normal status again.
This is what I think is the piece of code that causes this behavior:
//I took a video
__block NSString *messageType;
__block NSData *messageData;
__block NSString *messageText;
[...]
NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
NSString *videoPath = nil;
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
videoPath = [[NSTemporaryDirectory() stringByAppendingPathComponent:videoDirectory]stringByAppendingPathComponent:tempVideoFileName];
exportSession.outputURL = [NSURL fileURLWithPath:videoPath];
NSLog(#"videopath of your mp4 file = %#",videoPath); // PATH OF YOUR .mp4 FILE
exportSession.outputFileType = AVFileTypeMPEG4;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:{
NSLog(#"Export failed: %#", [[exportSession error] localizedDescription]);
[picker dismissViewControllerAnimated:YES completion:^{
[SVProgressHUD showErrorWithStatus:[[exportSession error] localizedDescription]];
}];
}
break;
case AVAssetExportSessionStatusCancelled:
NSLog(#"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:{
messageData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoPath]];
messageText = videoPath;
messageType = kMessageTypeVideo;
// This method sends asynchronously the data to the server
[self sendMediaType:messageType MessageData:messageData MessageText:messageText];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
break;
default:
break;
}
}];
}
Is there a way to avoid the appearance of the red status bar or at least the way I should use to make it disappear?

It turns out that in some way the recording session of the UIImagePickerController went in conflict with the AVAssetExportSession.
I resolved this issue by converting the video after having dismissed the UIImagePicker controller:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeImage, 0)
== kCFCompareEqualTo) {
[....]
}
else{
//Took a video
NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];
[picker dismissViewControllerAnimated:YES completion:^{
[self convertAndSendVideo:url];
}];
}
}
-(void)convertAndSendVideo:(NSURL *)url{
__block NSString *messageType;
__block NSData *messageData;
__block NSString *messageText;
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
NSString *videoPath = nil;
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
__block AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
videoPath = [[NSTemporaryDirectory() stringByAppendingPathComponent:videoDirectory]stringByAppendingPathComponent:tempVideoFileName];
exportSession.outputURL = [NSURL fileURLWithPath:videoPath];
NSLog(#"videopath of your mp4 file = %#",videoPath); // PATH OF YOUR .mp4 FILE
exportSession.outputFileType = AVFileTypeMPEG4;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:{
NSLog(#"Export failed: %#", [[exportSession error] localizedDescription]);
[SVProgressHUD showErrorWithStatus:[[exportSession error] localizedDescription]];
}
break;
case AVAssetExportSessionStatusCancelled:
NSLog(#"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:{
messageData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoPath]];
messageText = videoPath;
messageType = kMessageTypeVideo;
[self sendMediaType:messageType MessageData:messageData MessageText:messageText];
}
break;
default:
break;
}
}];
}
}

Related

Video export failed Show error AVAssetExportSessionStatusFailed

I have tried to find out regarding this issue but didn't find any exact solution for this.
NSString *strPath = #"video.mp4";
NSURL *URL = [NSURL fileURLWithPath:strPath];
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:URL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality];
exportSession.shouldOptimizeForNetworkUse = YES;
NSString *cachesFolder = [NSTemporaryDirectory() stringByAppendingPathComponent: [NSString stringWithFormat:#"%#", [strPath lastPathComponent]]];
NSURL *fileUrl = [NSURL fileURLWithPath:cachesFolder];
exportSession.outputURL = fileUrl;
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(#"Export failed");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(#"Export Completed");
break;
default:
break;
}
Log: Export failed
I can not comment :(
I just test your code and everything work fine.
Just check in debug "strPath" is correct (export mov file is in bundle)

Failed to convert .avi to .mp4 in iOS objective-c

I am using a camera to record video's and save them into my documents folder. The problem I am facing is that the video's I got from the camera are .avi files and have to be converted to .mp4 (or any other allowed format).
I use the code below:
SOURCE: iOS Convert AVI to MP4 Format programatically
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:#"MyVideo.mp4"];
NSURL *outputURL = [NSURL fileURLWithPath:filePath];
[self convertVideoToLowQuailtyWithInputURL:localUrl outputURL:outputURL handler:^(AVAssetExportSession *exportSession)
{
if (exportSession.status == AVAssetExportSessionStatusCompleted) {
// Video conversation completed
}
}];
- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL handler:(void (^)(AVAssetExportSession*))handler {
[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetPassthrough];
exportSession.outputURL = outputURL;
exportSession.outputFileType = AVFileTypeMPEG4;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
handler(exportSession);
}];
}
the exportSession status always fails. But when i try to convert a .mov into a .mp4 is does work.
How come I cannot convert .avi files into .mp4 files ?
Try to print the error message:
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(#"Export failed: %#", [[exportSession error] localizedDescription]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(#"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(#"Successfully");
break;
default:
break;
}
}];
}

Deleting File Path extension don't work, when we have to convert video format from .MOV to .MP4

As i select a video from Gallery i am getting selected file extension as .MOV so wanted to convert it to .MP4 researched but not getting how to do that in this case. If u have any idea please help.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
selectedVideoURL = info[UIImagePickerControllerMediaURL];
if( [picker sourceType] == UIImagePickerControllerSourceTypeCamera )
{
NSURL *videoURL=info[UIImagePickerControllerMediaURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
[library writeVideoAtPathToSavedPhotosAlbum:videoURL completionBlock:^(NSURL *assetURL, NSError *error )
{
//here is your URL : assetURL
NSLog(#"url is%#",assetURL);
PHFetchResult<PHAsset*> *assets = [PHAsset fetchAssetsWithALAssetURLs:#[assetURL]
options:nil];
PHAsset *asset1 = assets.firstObject;
[[PHImageManager defaultManager] requestAVAssetForVideo:asset1 options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
if ([asset isKindOfClass:[AVURLAsset class]]) {
AVURLAsset* urlAsset = (AVURLAsset*)asset;
NSNumber *size;
[urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
NSLog(#"size video of camera %f",[size floatValue]/(1024.0*1024.0)); //size is 43.703005
NSData *data = [NSData dataWithContentsOfURL:urlAsset.URL];
NSLog(#"length of camera %f",[data length]/(1024.0*1024.0)); // data size is 43.703005
sizeofVideo=[size floatValue]/(1024.0*1024.0);
NSLog(#"sizeofVideo arvin %f",sizeofVideo);
if (!sizeofVideo>50.00) {
selectedVideoURL=nil;
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Alert" message:#"size of video exist 50MB" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil];
[alert show];
attachnoteLbl.text=[NSString stringWithFormat:#"Attach Note:0"];
}
attachnoteLbl.text=[NSString stringWithFormat:#"Attach Note:1"];
}
}];
}];
}
else
{
NSURL *videoURL=info[UIImagePickerControllerReferenceURL];
NSLog(#" valid is%#",[info objectForKey:UIImagePickerControllerReferenceURL]);
//else this is valid : [info objectForKey:UIImagePickerControllerReferenceURL]];
PHFetchResult<PHAsset*> *assets = [PHAsset fetchAssetsWithALAssetURLs:#[videoURL]
options:nil];
PHAsset *asset1 = assets.firstObject;
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
// Check if video is supported for conversion or not
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
//Create Export session
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetLowQuality];
//Creating temp path to save the converted video
NSString* documentsDirectory= [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* myDocumentPath= [documentsDirectory stringByAppendingPathComponent:#"temp.mp4"];
NSURL *url = [[NSURL alloc] initFileURLWithPath:myDocumentPath];
NSData* data = [myDocumentPath dataUsingEncoding:NSUTF8StringEncoding];
//Check if the file already exists then remove the previous file
if ([[NSFileManager defaultManager]fileExistsAtPath:myDocumentPath])
{
[[NSFileManager defaultManager]removeItemAtPath:myDocumentPath error:nil];
}
exportSession.outputURL = url;
//set the output file format if you want to make it in other file format (ex .3gp)
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.shouldOptimizeForNetworkUse = YES;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status])
{
case AVAssetExportSessionStatusFailed:
NSLog(#"Export session failed");
break;
case AVAssetExportSessionStatusCancelled:
NSLog(#"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:
{
//Video conversion finished
NSLog(#"Successful!");
}
break;
default:
break;
}
}];
}
else
{
NSLog(#"Video file not supported!");
}
[[PHImageManager defaultManager] requestAVAssetForVideo:asset1 options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
if ([asset isKindOfClass:[AVURLAsset class]]) {
AVURLAsset* urlAsset = (AVURLAsset*)asset;
NSNumber *size;
[urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
NSLog(#"size video of phassetis %f",[size floatValue]/(1024.0*1024.0)); //size is 43.703005
NSData *data = [NSData dataWithContentsOfURL:urlAsset.URL];
NSLog(#"length %f",[data length]/(1024.0*1024.0)); // data size is 43.703005
sizeofVideo=[size floatValue]/(1024.0*1024.0);
NSLog(#"sizeofVideo arvin %f",sizeofVideo);
if (sizeofVideo>50.00) {
selectedVideoURL=nil;
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Alert" message:#"size of video exist 50MB" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil];
[alert show];
attachnoteLbl.text=[NSString stringWithFormat:#"Attach Note:0"];
}
attachnoteLbl.text=[NSString stringWithFormat:#"Attach Note:1"];
}
}];
}
[picker dismissViewControllerAnimated:YES completion:NULL];
_importView.hidden=YES;
}
I have tried the following way by deleting the file extension from.MOV to .MP4 while uploading it but din't worked.So i think need to convert it in the begging only while selecting it from gallery or camera.But not getting how to do that.Any help is appreciated
-(void)afnetworking{
NSURL *videoURL = [NSURL fileURLWithPath:myDocumentPath];
NSData *data = [NSData dataWithContentsOfURL:videoURL];
if(data)
{
// NSString *videoName = [[videoUrl lastPathComponent]stringByDeletingPathExtension];
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
[bodyData appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *tmpfileinfo = [NSString stringWithFormat:#"Content-Disposition: form-data; name=\"video_clip\"; filename=\"%#\"\r\n",videoData];
[bodyData appendData:[tmpfileinfo dataUsingEncoding:NSUTF8StringEncoding]];
[bodyData appendData:[#"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[bodyData appendData:[NSData dataWithData:videoData]];
}
1) First of all you have to select video from photogallery, which you are already doing.
2) After that you have to export selected video to document directory.
3) Then you have to select video from document directory path while you are uploading to server.
// Create the asset url with the video file
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
// Check if video is supported for conversion or not
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
//Create Export session
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetLowQuality];
//Creating temp path to save the converted video
NSString* documentsDirectory= [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* myDocumentPath= [documentsDirectory stringByAppendingPathComponent:#"temp.mp4"];
NSURL *url = [[NSURL alloc] initFileURLWithPath:myDocumentPath];
//Check if the file already exists then remove the previous file
if ([[NSFileManager defaultManager]fileExistsAtPath:myDocumentPath])
{
[[NSFileManager defaultManager]removeItemAtPath:myDocumentPath error:nil];
}
exportSession.outputURL = url;
//set the output file format if you want to make it in other file format (ex .3gp)
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.shouldOptimizeForNetworkUse = YES;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status])
{
case AVAssetExportSessionStatusFailed:
NSLog(#"Export session failed");
break;
case AVAssetExportSessionStatusCancelled:
NSLog(#"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:
{
//Video conversion finished
NSLog(#"Successful!");
}
break;
default:
break;
}
}];
}
else
{
NSLog(#"Video file not supported!");
}
EDIT
-(void)afnetworking{
NSUrl *videoURL = [NSURL fileURLWithPath:myDocumentPath];
NSData *data = [NSData dataWithContentsOfURL:videoURL];
if(data)
{
NSString *videoName = [[videoUrl lastPathComponent]stringByDeletingPathExtension];
NSData *videoData = [NSData dataWithContentsOfURL:selectedVideoURL];
[bodyData appendData:[[NSString stringWithFormat:#"\r\n--%#\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *tmpfileinfo = [NSString stringWithFormat:#"Content-Disposition: form-data; name=\"video_clip\"; filename=\"%#.mp4\"\r\n",videoName];
[bodyData appendData:[tmpfileinfo dataUsingEncoding:NSUTF8StringEncoding]];
[bodyData appendData:[#"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[bodyData appendData:[NSData dataWithData:videoData]];
}

Why don't I get video when exporting a movie using AVAssetExportSession?

It is trimming the audio, but the video is blank.
This is the function that initiates trimming
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor blackColor];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(finishedTrimming:)
name:#"videoFinishedTrimming"
object:nil];
NSURL *furl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:#"capture0.mp4"]];
//[self playVideoWithURL:furl]; //Play original video
//Play trimmed video
CMTime startTrim = CMTimeMake(0, 1);
CMTime endTrim = CMTimeMake(2,1);
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTrim, endTrim);
[ProcessingHelper trimAssetWithURL:furl andRange:exportTimeRange];
}
This is the function that exports and trims the video.
+(void)trimAssetWithURL:(NSURL *)urlIn andRange:(CMTimeRange)timeRangeIn
{
AVAsset *videoAsset = [AVAsset assetWithURL:urlIn];
//Creates the session with the videoasset
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:videoAsset presetName:AVAssetExportPresetHighestQuality];
//Creates the path to export to - Saving to temporary directory
NSString* filename = [NSString stringWithFormat:#"TrimmedCapture%d.mp4", 0];
NSString* path = [NSTemporaryDirectory() stringByAppendingPathComponent:filename];
//Checks if there is already a file at the output URL. session will not overwrite previous data
if ([[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSLog(#"Removing item at path: %#", path);
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}
//Set the output url
exportSession.outputURL = [NSURL fileURLWithPath:path];
//Set the output file type
exportSession.outputFileType = AVFileTypeMPEG4; //AVFileTypeAC3; // AVFileTypeMPEGLayer3; // AVFileTypeWAVE; // AVFileTypeQuickTimeMovie;
exportSession.timeRange = timeRangeIn;
exportSession.metadata = nil;
//Exports!
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch (exportSession.status) {
case AVAssetExportSessionStatusCompleted:{
NSLog(#"Export Complete");
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:exportSession.outputURL, #"outputURL", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:#"videoFinishedTrimming" object:self userInfo:options];
break;
}
case AVAssetExportSessionStatusFailed:
NSLog(#"Export Error: %#", [exportSession.error description]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(#"Export Cancelled");
break;
default:
break;
}
}];
exportSession = nil;
}
This is the function that initiates the playing of the video
-(void)finishedTrimming:(NSNotification *)notification
{
NSDictionary *userInfo = notification.userInfo;
NSURL *outputURL = [userInfo objectForKey:#"outputURL"];
[self playVideoWithURL:outputURL];
}
This is the function that plays the video
-(void)playVideoWithURL:(NSURL *)furl
{
NSData *movieData;
NSError *dataReadingError = nil;
movieData = [NSData dataWithContentsOfURL: furl options:NSDataReadingMapped error:&dataReadingError];
if(movieData != nil)
NSLog(#"Successfully loaded the data.");
else
NSLog(#"Failed to load the data with error = %#", dataReadingError);
//AVPlayer
self.avPlayer = [AVPlayer playerWithURL:furl];
AVPlayerLayer *avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
avPlayerLayer.frame = self.vPlayBackMovie.bounds;
avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
avPlayerLayer.needsDisplayOnBoundsChange = YES;
[self.vPlayBackMovie.layer addSublayer:avPlayerLayer];
self.vPlayBackMovie.layer.needsDisplayOnBoundsChange = YES;
[self.avPlayer play];
}
Thanks ChrisH, you were right! The Export was taking place on another thread so in the handler I need to get the main queue...
I needed to get the main thread after
case AVAssetExportSessionStatusCompleted:{
dispatch_async(dispatch_get_main_queue(), ^{
//post the notification!
});
break;
}

Cutting video on iPhone

I have a video file from the device camera -- stored as /private/var/mobile/Media/DCIM/100APPLE/IMG_0203.MOV, for example, and I need to cut the first 10 seconds of this video. What API or libraries I can use?
I found solution with standard API: AVAssetExportSession
- (void)getTrimmedVideoForFile:(NSString *)filePath withInfo:(NSArray *)info
{
//[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:filePath] options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES);
// NSString *outputURL = paths[0];
NSFileManager *manager = [NSFileManager defaultManager];
// [manager createDirectoryAtPath:outputURL withIntermediateDirectories:YES attributes:nil error:nil];
// outputURL = [outputURL stringByAppendingPathComponent:#"output.mp4"];
NSString *outputURL = [NSString stringWithFormat:#"/tmp/%#.mp4", [info objectAtIndex:2]];
NSLog(#"OUTPUT: %#", outputURL);
// Remove Existing File
// [manager removeItemAtPath:outputURL error:nil];
if (![manager fileExistsAtPath:outputURL]) {
exportSession.outputURL = [NSURL fileURLWithPath:outputURL];
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTime start = kCMTimeZero;
CMTime duration = kCMTimeIndefinite;
if ([[NSString stringWithFormat:#"%#", [info objectAtIndex:3]] floatValue] > 20.0) {
start = CMTimeMakeWithSeconds(1.0, 600);
duration = CMTimeMakeWithSeconds(10.0, 600);
}
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
switch (exportSession.status) {
case AVAssetExportSessionStatusCompleted:
NSLog(#"Export Complete %d %#", exportSession.status, exportSession.error);
[self sendVideoPreview:info];
break;
case AVAssetExportSessionStatusFailed:
NSLog(#"Failed:%#",exportSession.error);
// [self addToDelayed:info withAction:#"add"];
break;
case AVAssetExportSessionStatusCancelled:
NSLog(#"Canceled:%#",exportSession.error);
// [self addToDelayed:info withAction:#"add"];
break;
default:
break;
}
}];
} else {
[self sendVideoPreview:info];
}

Resources