0

My goal is to make a video out of a short sequence of opengl frames (around 200 frames). So in order to do this, I use the following code to create a array of images:

NSMutableArray* images = [NSMutableArray array];
KTEngine* engine = [KTEngine sharedInstance]; //Opengl - based engine

for (unsigned int i = engine.animationContext.unitStart; i < engine.animationContext.unitEnd ; ++i)
{
    NSLog(@"Render Image %d", i);
    [engine.animationContext update:i];
    [self.view setNeedsDisplay];
    [images addObject:[view snapshot]];
}

NSLog(@"Total image rendered %d", [images count]);
[self createVideoFileFromArray:images];

So this works perfectly fine on simulator, but not on device (retina iPad). So my guess is that the device does not support so many UIimages (specially in 2048*1536). The crash always happends after 38 frames or so.

Now as for the solution, I thought to create a video for each 10 frames, and then attached them all together, but when can I know if I have enough space (is the autorelease pool drained?).

Maybe I should use a thread, process 10 images, and fire it again for the next 10 frames once it's over?

Any idea?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Zerto
  • 41
  • 3

1 Answers1

0

It seems quite likely that you're running out of memory.

To reduce memory usage, you could try to store the images as NSData using the PNG or JPG format instead. Both PNG's and JPG's are quite small when represented as data, but loading them into UIImage objects can be very memory consuming.

I would advice you to do something like below in your loop. The autorelease pool is needed to drain the returned snapshot on each iteration.

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIImage *image = [view snapshot];
NSData *imageData = UIImagePNGRepresentation(image);
[images addObject:imageData];
[pool release];

This of course requires your createVideoFileFromArray: method to handle pure image data instead of UIImage objects, but that should probably be feasible to implement.

Anton
  • 5,932
  • 5
  • 36
  • 51