title: Split video in iOS
body: <p>i have to split the video into two parts.i am using with this trim function twicely is that good approach i have read the <code>AVFoundation</code> frame work but didn't found any direct solution to split the video.but there are some iPhone Apps which are splitting the video very smoothly.are they using the trim function ? need suggestion </p>
  
  <pre><code>-(void)splitSecondVideo{
      NSString *deleteVideo = [_videoPath path];
  
      AVURLAsset *asset = [AVURLAsset URLAssetWithURL:_videoPath options:nil];
  
      AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
       NSString *outputURL = nil;
       NSString *videoFileName = nil;
       videoFileName = [SPUtility getDefaultVideoName];
       outputURL = [NSString stringWithFormat:@"%@/%@.mov", _clipFolderPath, videoFileName];
  
      NSFileManager *manager = [NSFileManager defaultManager];
      [manager createDirectoryAtPath:outputURL withIntermediateDirectories:YES attributes:nil error:nil];
      [manager removeItemAtPath:outputURL error:nil] ;
       exportSession.outputURL = [NSURL fileURLWithPath:outputURL];
       exportSession.shouldOptimizeForNetworkUse = YES;
       exportSession.outputFileType = AVFileTypeQuickTimeMovie;
       // Trim to half duration
       double halfDuration = CMTimeGetSeconds([asset duration])/2.0;
       double fullDuration = CMTimeGetSeconds([asset duration]);
  
       CMTime firsthalfDuration = CMTimeMakeWithSeconds(halfDuration, 1);
       CMTime secondhalfDuration = CMTimeMakeWithSeconds(fullDuration, 1);
  
       CMTimeRange secondrange = CMTimeRangeMake(firsthalfDuration, secondhalfDuration);
  
       exportSession.timeRange = secondrange;
  
       [exportSession exportAsynchronouslyWithCompletionHandler:^(void)
       {
       switch (exportSession.status) {
       case AVAssetExportSessionStatusCompleted:
       [manager removeItemAtPath:deleteVideo error:nil];
       NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
       break;
       case AVAssetExportSessionStatusFailed:
       NSLog(@"Failed:%@",exportSession.error);
       break;
       case AVAssetExportSessionStatusCancelled:
       NSLog(@"Canceled:%@",exportSession.error);
       break;
       default:
       break;
       }
  
       }];
  
  
  }
  </code></pre>