title: The samples read from the AVAssetReader is not in order
body: <p>I have a trouble while reading the sample buffers from a file using AVAssetreader. The timestamps of the samples read seem to be out of order. Is this the expected result or is there something I am doing wrong. Below is the reading and writing code I am using -</p>
  
  <pre><code>[assetWriterInput requestMediaDataWhenReadyOnQueue:serializationQueue usingBlock:^{
      if (finished)
          return;
  
      BOOL completedOrFailed = NO;
  
      // Read samples in a loop as long as the asset writer input is ready
      while ([assetWriterInput isReadyForMoreMediaData] &amp;&amp; !completedOrFailed)
      {
          CMSampleBufferRef sampleBuffer = [assetReaderOutput copyNextSampleBuffer];
          CMTime originalTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
  
          if (sampleBuffer != NULL)
          {
  
              CMTime cmm1   =   CMSampleBufferGetOutputDuration(sampleBuffer);
  
              NSLog(@"Timestamps ==  %f",time);
  
  
              CMSampleBufferRef newSampleBuffer;
              CMSampleTimingInfo sampleTimingInfo;
  
              sampleTimingInfo.duration = cmm1;
              float milliseconds = videoPTM * 600;
              sampleTimingInfo.presentationTimeStamp = CMTimeMake((int)milliseconds, 600);
              sampleTimingInfo.decodeTimeStamp = kCMTimeInvalid;
  
              CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault,
                                                    sampleBuffer,
                                                    1,
                                                    &amp;sampleTimingInfo,
                                                    &amp;newSampleBuffer);
  
              BOOL success = YES;
              success  = [assetWriterInput appendSampleBuffer:newSampleBuffer];
  
              CFRelease(newSampleBuffer);
              newSampleBuffer = NULL;
  
              CFRelease(sampleBuffer);
              sampleBuffer = NULL;
  
              completedOrFailed = !success;
  
              videoPTM+=CMTimeGetSeconds(cmm1);
  
          }
          else
          {
              completedOrFailed = YES;
          }
      }
  
      if (completedOrFailed)
          [self callCompletionHandlerIfNecessary];
  </code></pre>
  
  <p>When I print the timestamps of the samples read they are not in order like this...</p>
  
  <pre><code>            Video Timestamps ==  6.971667
              Video Timestamps ==  7.055000
              Video Timestamps ==  7.220000
              Video Timestamps ==  7.136667
              Video Timestamps ==  7.386667
              Video Timestamps ==  7.303333
              Video Timestamps ==  7.470000
              Video Timestamps ==  7.635000
  </code></pre>
  
  <p>Please let me know the reason of the same and how I can create a copy of the samples with a different presentation time.</p>