-->

Capturing the output of a video file for frame by

2020-07-27 06:01发布

问题:

I am trying to grab the individual frames from a video file (7 seconds long) and running into huge memory issues.

I am loading up an asset with AVURLAsset then creating an AVAssetReader and an accompanying AVAssetReaderTrackOutput (with pixel format kCVPixelFormatType_32BGRA). Everything seems to work just fine except for the massive memory hit that ends up getting my app shutdown by the OS almost instantly.

As soon as I call [myAVAssetReader startReading] memory spikes up 25 megs and it only gets worse from there.

Even if I just call [myAVAssetReader startReading] then [myAVAssetReader cancelReading] and [myAVAssetReader release] the 25 megs is never released. It only gets worse once I go into a loop gathering frames:

CMSampleBufferRef sample = [output copyNextSampleBuffer];

    while( sample != NULL )
    {
         CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer( sample );

         // Lock the image buffer
         CVPixelBufferLockBaseAddress( imageBuffer, 0 );

            // Do stuff with the imageBuffer

         // We unlock the  image buffer
         CVPixelBufferUnlockBaseAddress( imageBuffer, 0 );

         // done with the sample
         CFRelease( sample );

         sample = [output copyNextSampleBuffer];
    }

Any clues as to how to free the memory that the AVAssetReader is using?

标签: iphone ios video