title: Issue in creating video from array of image
body: <p>I used the following code to generate the video from array of images and audio (pre recorded)..</p>
  
  <pre><code>- (void)viewDidLoad
  {
      imagearray=[[NSMutableArray alloc]initWithObjects:@"Quiz pic1.jpg",@"Quiz pic2.jpg",@"Quiz pic3.jpg",@"Quiz pic6.jpg",@"Quiz pic7.jpg",nil];
      image1array=[[NSMutableArray alloc]init];
      for (int i=0; i&lt;[imagearray count]; i++)
      {
          UIImage *aimage=[UIImage imageNamed:[imagearray objectAtIndex:i]];
          [image1array addObject:aimage];
      }
      NSLog(@"%@",image1array);
      ImageVideoPath=@"/Users/image/Library/Application Support/iPhone Simulator/4.3/Applications/6CC91208-5819-4BFF-B868-6605887861EB/Output";
      FinalVideoPath=@"/Users/image/Library/Application Support/iPhone Simulator/4.3/Applications/6CC91208-5819-4BFF-B868-6605887861EB/VideoOutput";
      CGSize size;
      UIImage *image=[UIImage imageNamed:[imagearray objectAtIndex:0]];
      size=image.size;
      NSString *audioFilePath;
      int duration=10;
      //[self pixelBufferFromCGImage:[[image1array objectAtIndex:0] CGImage]];
      [self writeImageAndAudioAsMovie:image andAudio:audioFilePath duration:duration];
  
      //[self pixelBufferFromCGImage:[image CGImage] andSize:size];
      [super viewDidLoad];
  }
  
  - (void)writeImageAndAudioAsMovie:(UIImage*)image andAudio:(NSString *)audioFilePath duration:(int)duration {
      NSLog(@"start make movie: length:%d",duration);
      NSError *error = nil;
      AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:ImageVideoPath] fileType:AVFileTypeQuickTimeMovie
                                                                error:&amp;error];
      NSParameterAssert(videoWriter);
      if ([[NSFileManager defaultManager] fileExistsAtPath:ImageVideoPath]) 
          [[NSFileManager defaultManager] removeItemAtPath:ImageVideoPath error:nil];
  
      NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecH264, AVVideoCodecKey,
                                     [NSNumber numberWithInt:image.size.width],AVVideoWidthKey,[NSNumber numberWithInt:image.size.height], AVVideoHeightKey,nil];
      AVAssetWriterInput* writerInput = [[AVAssetWriterInput
                                          assetWriterInputWithMediaType:AVMediaTypeVideo
                                          outputSettings:videoSettings] retain];
  
      AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput sourcePixelBufferAttributes:nil];
      NSParameterAssert(writerInput);
      NSParameterAssert([videoWriter canAddInput:writerInput]);
      writerInput.expectsMediaDataInRealTime = YES;
      [videoWriter setShouldOptimizeForNetworkUse:YES];
      [videoWriter addInput:writerInput];
  
      //Start a session:
      [videoWriter startWriting];
      [videoWriter startSessionAtSourceTime:kCMTimeZero];
  
      //Write samples:
      CVPixelBufferRef buffer = [self pixelBufferFromCGImage:image.CGImage];
      [adaptor appendPixelBuffer:buffer withPresentationTime:kCMTimeZero];
  
      //Finish the session:
      [videoWriter endSessionAtSourceTime:CMTimeMake(duration, 1)];
      [writerInput markAsFinished];
      [videoWriter finishWriting];
  
      CVPixelBufferPoolRelease(adaptor.pixelBufferPool);
      [videoWriter release];
      [writerInput release];
      audioFilePath=[[NSBundle mainBundle]pathForResource:@"Video" ofType:@"mp3"];
      NSLog(@"%@",audioFilePath);
      [self addAudioToFileAtPath:ImageVideoPath andAudioPath:audioFilePath];
  }
  
  -(CVPixelBufferRef)pixelBufferFromCGImage: (CGImageRef) image{
      float width = CGImageGetWidth(image);
      float height = CGImageGetHeight(image);
  
      NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                               [NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
                               [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
                               nil];
      CVPixelBufferRef pxbuffer = NULL;
      CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, width,height, kCVPixelFormatType_32ARGB,(CFDictionaryRef)options,&amp;pxbuffer);
  
      NSParameterAssert(status == kCVReturnSuccess &amp;&amp; pxbuffer != NULL);
  
      CVPixelBufferLockBaseAddress(pxbuffer, 0);
      void *pxdata = CVPixelBufferGetBaseAddress(pxbuffer);
  
      NSParameterAssert(pxdata != NULL);
  
      CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
      CGContextRef context = CGBitmapContextCreate(pxdata,width,height,8,4*width,rgbColorSpace,kCGImageAlphaNoneSkipFirst);
  
      NSParameterAssert(context);
      CGContextDrawImage(context, CGRectMake(0, 0,width, height), image);
  
      CGColorSpaceRelease(rgbColorSpace);
      CGContextRelease(context);
  
      CVPixelBufferUnlockBaseAddress(pxbuffer, 0);
  
      return pxbuffer;
  }
  
  -(void) addAudioToFileAtPath:(NSString *)vidoPath andAudioPath:(NSString *)audioFilePath{
      AVMutableComposition* mixComposition = [AVMutableComposition composition];
      NSLog(@"%@ %@",ImageVideoPath,audioFilePath);
      NSURL* audio_inputFileUrl = [NSURL fileURLWithPath:audioFilePath];
      NSURL* video_inputFileUrl = [NSURL fileURLWithPath:ImageVideoPath];
      NSLog(@"%@",video_inputFileUrl);
      NSString *outputFilePath = FinalVideoPath;
      NSURL* outputFileUrl = [NSURL fileURLWithPath:outputFilePath];
  
      if ([[NSFileManager defaultManager] fileExistsAtPath:outputFilePath]) 
          [[NSFileManager defaultManager] removeItemAtPath:outputFilePath error:nil];
  
     AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audio_inputFileUrl options:nil];
  AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:video_inputFileUrl options:nil];
  NSLog(@"asset:%@",videoAsset);
  NSArray *tracks1=[videoAsset tracksWithMediaType:AVMediaTypeVideo];
  if ([tracks1 count]&gt;0)
  {
      //CMTimeRange video_timeRange = CMTimeRangeMake(kCMTimeZero,videoAsset.duration);
      AVAssetTrack *videoAssetTrack=[tracks1 objectAtIndex:0];
      AVMutableCompositionTrack *a_compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
  
      [a_compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,videoAsset.duration) ofTrack:videoAssetTrack atTime:kCMTimeZero error:nil];  
  
  }
  
  NSArray *tracks = [audioAsset tracksWithMediaType:AVMediaTypeAudio];
  if([tracks count]&gt;0)
  {
      AVAssetTrack * audioAssetTrack = [tracks objectAtIndex:0];
      AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio 
                                                                                     preferredTrackID: kCMPersistentTrackID_Invalid];
  
      [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,audioAsset.duration) ofTrack:audioAssetTrack atTime:kCMTimeZero error:nil];  
  
  
      //nextClipStartTime = CMTimeAdd(nextClipStartTime, a_timeRange.duration);
      [audioAsset release];audioAsset = nil;
  }
  
  
      AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];   
      _assetExport.outputFileType = AVFileTypeMPEG4;
      _assetExport.outputURL = outputFileUrl;
  
      [_assetExport exportAsynchronouslyWithCompletionHandler:
       ^(void ) {
           switch (_assetExport.status) 
           {
               case AVAssetExportSessionStatusCompleted:
                   //export complete 
                   NSLog(@"Export Complete");
                   break;
               case AVAssetExportSessionStatusFailed:
                   NSLog(@"Export Failed");
                   NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]);
                   //export error (see exportSession.error)  
                   break;
               case AVAssetExportSessionStatusCancelled:
                   NSLog(@"Export Failed");
                   NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]);
                   //export cancelled  
                   break;
           }
       }];    
  }
  </code></pre>
  
  <p>I found that one of the video file is created from the method <code>writeImageAndAudioAsMovie</code> but itz nt supporting any player in my machine...
  I don't knw wat I'm missing? Any suggestions plz....</p>