1

I have been trying to create a circular buffer of 60 frames of video from that come from AVCaptureOutput and then I need to write the frames to AVAssetWriter after an event occurs. I think it would have to work in a similar way to how this app http://itunes.apple.com/us/app/precorder-video-camera-for/id412558814?mt=8 records a set amount before the record button is pressed.

The prior method that I have been using for the circular buffer was to add the sampleBuffer from the output into an NSArray, by means of converting it to a UIImage. This works fine except that, as far as I can see, the array fills up with uncompressed video frames too quickly (giving me memory warnings and then crashing) and also if the video quality is set high, the frame rate is too slow, due to the conversions to UIImage objects. So therefore now I have been trying to add the sampleBuffer into a CFMutableArray - as it means that I don't have to convert it to a UIImage, thus hopefully picking up the frame rate. However, there are very very few examples of anyone having done this. I read Save sampleBuffer in array (AVFoundation) and understood to do the following:

To initialise:

CFMutableArrayRef arrayOne = CFArrayCreateMutable( NULL, 0, &kCFTypeArrayCallBacks );

To insert:

CFArrayInsertValueAtIndex(arrayOne, index, sampleBuffer);

To convert back to sampleBuffer:

CMSampleBufferRef newSampleBuffer = (CMSampleBufferRef)CFArrayGetValueAtIndex(arrayOne, cfarrIndex);

However, when I go to use the the 'newSampleBuffer', it doesn't allow me to use it, generally stopping the code or giving a bad access error.

So I guess my question is, does anyone know if what I am trying to do is possible?? Or if there was any other way to do this?

Thanks in advance!

3
  • Unfortunately, I don't think you're going to be able to avoid memory issues by storing these pixel buffers in an array instead of UIImages. For both, the element determining memory consumption is the size of an uncompressed image. For a 640x480 RGBA frame, that's 1.2 MB (3.7 MB for 720p). 60 frames of that is 73.7 MB, which puts you in dangerous territory for even the iPhone 4S. Storing 60 720p frames in memory this way is out of the question for all current devices. Commented May 24, 2012 at 16:00
  • Thanks for your reply. I thought that might be the case. I saw itunes.apple.com/us/app/precorder-video-camera-for/… but I think I need to figure out another way of doing it. Commented May 24, 2012 at 21:11
  • 2
    In that case, I bet they continually record a series of short videos to disk, then delete older segments once they pass an age threshold. That's reasonably easy to set up. Commented May 24, 2012 at 22:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.