title: What exactly does AVFoundation's AVAssetWriterInput expectsMediaDataInRealTime property do?
body: <p>I am working on an app that reads media data from disk, converts it into the appropriate pixel format and then passes it off to AVAssetWriter for compression and writing to disk. I am doing my own reading an interleaving and not using AVAssetReader. My reader ensures that exactly one frame's worth of video data and one frame's worth of audio data are presented in a serial fashion. The problem I am having is if I don't set the expectsMediaDataInRealTime property to <strong>YES</strong>, the video asset writer will always return <strong>NO</strong> for isReadyForMoreMediaData after exactly 30 frames. If I stop writing before 30 frames, it works fine and the output file is valid. However, if I set expectsMediaDataInRealTime to YES, it works perfectly for the entire duration, which can be several thousand frames. After starting a transcode operation with expectsMediaDataInRealTime set to YES, I watched the app's memory usage over the course of compressing a very long video and there wasn't any unreasonable memory usage nor any memory leaks. And the resulting MOV file did appear to be written fairly normal, e.g. the audio data was interleaved with the video data as one would expect.</p>
  
  <p>So, why would I ever set expectsMediaDataInRealTime to NO if there is no apparent downside to setting it to YES? Does this only apply when using an Apple API to read data (using AVAssetReader)? The documentation says that this property controls writing "media data in an ideal interleaving pattern for efficiency in storage and playback," but when expectsMediaDataInRealTime is set to YES, isReadyForMoreMediaData never returns NO and the file appears to be written perfectly. So, if the AVAssetWriter can do this when this property set to YES, why can't it do it when set to NO? The source is exactly the same.</p>
  
  <p>What, exactly, does this property do other than "ensure that the value of readyForMoreMediaData is calculated appropriately" (which means absolutely nothing to me)?</p>