title: How to control video frame rate with AVAssetReader and AVAssetWriter?
body: <p>We are trying to understand how to control/specify the frame rate for videos that we are encoding with <code>AVAssetReader</code> and <code>AVAssetWriter</code>. Specifically, we are are using <code>AVAssetReader</code> and <code>AVAssetWriter</code> to transcode/encode/compress a video that we have accessed from the photo/video gallery. We are able to control things like bit rate, aspect ratio changes, etc., but cannot figure out how to control the frame rate. To be specific, we'd like to be able to take as input a 30 FPS video that's 5 minutes long and emit a 5 minute video at 15 FPS.</p>
  
  <p>Our current loop that processes sample buffers is:</p>
  
  <pre><code>[writer startWriting];
  [writer startSessionAtSourceTime:kCMTimeZero];
  [videoReader startReading];
  
  [videoWriterInput requestMediaDataWhenReadyOnQueue:videoEncoderQueue usingBlock:
   ^{         
      while ([videoWriterInput isReadyForMoreMediaData]) {
          CMSampleBufferRef sampleBuffer;
  
          if ([videoReader status] == AVAssetReaderStatusReading 
              &amp;&amp; (sampleBuffer = [videoReaderTrackOutput copyNextSampleBuffer])) {
              if (sampleBuffer) {
                  BOOL result = [videoWriterInput appendSampleBuffer:sampleBuffer];
                  CFRelease(sampleBuffer);
  
                  if (!result) {
                      [videoReader cancelReading];
                      break;
                  }
              }
          } else {
              // deal with status other than AVAssetReaderStatusReading
              [videoWriterInput markAsFinished];
              // [...]
              break;
          }
      }
   }];
  </code></pre>
  
  <p>How do we augment or change this so that we could control the frame rate of the created video? We cannot seem to find a sample in SO or anywhere else that clearly explains how to do this. I think we're supposed to use <code>CMTime</code> and probably some other methods other than the ones in the code sample above, but the details aren't clear.</p>