title: How to do Slow Motion video in IOS
body: <p>I have to do "<strong>slow motion</strong>" in a video file along with audio, in-between some frames and need to <strong>store</strong> the ramped video as a new video.</p>
  
  <p>Ref: <a href="http://www.youtube.com/watch?v=BJ3_xMGzauk">http://www.youtube.com/watch?v=BJ3_xMGzauk</a> (watch from 0 to 10s)</p>
  
  <p>From my analysis, I've found that <strong>AVFoundation</strong> framework can be helpful.</p>
  
  <p>Ref:
  <a href="http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html">http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html</a></p>
  
  <p>Copy and pasted from the above link:</p>
  
  <p>"
  Editing
  AV Foundation uses compositions to create new assets from existing pieces of media (typically, one or more video and audio tracks). You use a mutable composition to add and remove tracks, and adjust their temporal orderings. You can also set the relative volumes and ramping of audio tracks; and set the opacity, and opacity ramps, of video tracks. A composition is an assemblage of pieces of media held in memory. When you export a composition using an export session, it's collapsed to a file.
  On iOS 4.1 and later, you can also create an asset from media such as sample buffers or still images using an asset writer.</p>
  
  <p>"</p>
  
  <p>Questions:
  <strong>Can I do " slow motion " the video/audio file using the AVFoundation framework ? Or Is there any other package available? If i want to handle audio and video separately, please guide me how to do?</strong></p>
  
  <p><strong>Update :: Code For AV Export Session :</strong></p>
  
  <pre><code> NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *outputURL = paths[0];
      NSFileManager *manager = [NSFileManager defaultManager];
      [manager createDirectoryAtPath:outputURL withIntermediateDirectories:YES attributes:nil error:nil];
      outputURL = [outputURL stringByAppendingPathComponent:@"output.mp4"];
      // Remove Existing File
      [manager removeItemAtPath:outputURL error:nil];
      AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:self.inputAsset presetName:AVAssetExportPresetLowQuality];
      exportSession.outputURL = [NSURL fileURLWithPath:outputURL]; // output path;
      exportSession.outputFileType = AVFileTypeQuickTimeMovie;
      [exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
          if (exportSession.status == AVAssetExportSessionStatusCompleted) {
              [self writeVideoToPhotoLibrary:[NSURL fileURLWithPath:outputURL]];
              ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
              [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:outputURL] completionBlock:^(NSURL *assetURL, NSError *error){
                  if (error) {
                      NSLog(@"Video could not be saved");
                  }
              }];
          } else {
              NSLog(@"error: %@", [exportSession error]);
          }
      }];
  </code></pre>