views:

63

answers:

1

How can I calculate the progress of an AVAssetWriter process? So if I have something like:

[assetWriterInput requestMediaDataWhenReadyOnQueue:queue usingBlock:^{
  while (1){
    if ([assetWriterInput isReadyForMoreMediaData]) {
      CMSampleBufferRef sampleBuffer = [audioMixOutput copyNextSampleBuffer];
      if (sampleBuffer) {
        [assetWriterInput appendSampleBuffer:sampleBuffer];
        CFRelease(sampleBuffer);
      } else {
        [assetWriterInput markAsFinished];
        break;
      }
    }
  }
}];

what can I be pulling (or polling) during the loop to figure out how many x of y I've completed?

Thanks.

+1  A: 

The sample buffer has several time stamps on them. You could get the presentation time stamp with a call to:

CMTime presTime = CMSampleBufferGetPresentationTimeStamp( sampleBuffer );

You could then use that to determine how far you are into your source for the input buffer. presTime / duration should give you a 0.0 to 1.0 value representing the approximate progress. If you needed to be more precise you could try to factor in the duration of the samples in the sample buffer using CMSampleBufferGetDuration().

If the presentation time does not work for you look at the other time stamps nearby in the header.

Jon Steinmetz