我正在制作一个从电影中去除帧的程序。这在 iOS 7 上的 Xcode 5.0 模拟器中。我试图放入这个数组的对象数量是 447。(似乎没有那么多)。
由于数组大小不够大,我的程序由于内存泄漏而不断崩溃?(不知道这种说法是否正确)或由于其他原因。仅对于帧数大于 350 的视频,它在 for 循环中始终失败。较少帧的视频可以正常工作。
只是预感它与我将大型原始帧图像存储到数组中的事实有关吗?我没有缩小框架图片?
CODE:
NSMutableArray* allFrames = [[NSMutableArray alloc] init];
// get each frame
for (int k=0; k< totalFrames; k++)
{
int timeValue = timeValuePerFrame * k;
CMTime frameTime;
frameTime.value = timeValue;
frameTime.timescale = movie.duration.timescale;
frameTime.flags = movie.duration.flags;
frameTime.epoch = movie.duration.epoch;
CMTime gotTime;
CGImageRef myRef = [generator copyCGImageAtTime:frameTime actualTime:&gotTime error:nil];
[allFrames addObject:[UIImage imageWithCGImage:myRef]];
if (gotTime.value != frameTime.value)
NSLog (@"requested %lld got %lld for k %d", frameTime.value, gotTime.value, k);
//cleanup?
CFRelease(myRef);
}
ERROR:
2013-11-03 20:18:24.746 test[42139:a0b] requested 9925 got 9921 for k 397
2013-11-03 20:18:25.122 test[42139:a0b] requested 9950 got 9946 for k 398
everseHD(42046,0xb029b000) malloc: *** mmap(size=8298496) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
2013-11-03 20:10:31.936 ReverseHD[42046:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x020305e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01db38b6 objc_exception_throw + 44
2 CoreFoundation 0x01fe2c3c -[__NSArrayM insertObject:atIndex:] + 844
3 CoreFoundation 0x01fe28e0 -[__NSArrayM addObject:] + 64
4 ReverseHD 0x00003131 -[v1ViewController extractImagesFromMovie] + 3089
5 libobjc.A.dylib 0x01dc5874 -[NSObject performSelector:withObject:withObject:] + 77
6 UIKit 0x00b27c8c -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x00b27c18 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x00c1f6d9 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x00c1fa9c -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x00c1e815 -[UIControl touchesBegan:withEvent:] + 254
11 UIKit 0x00b64efb -[UIWindow _sendTouchesForEvent:] + 386
12 UIKit 0x00b65d34 -[UIWindow sendEvent:] + 1232
13 UIKit 0x00b39a36 -[UIApplication sendEvent:] + 242
14 UIKit 0x00b23d9f _UIApplicationHandleEventQueue + 11421
15 CoreFoundation 0x01fb98af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x01fb923b __CFRunLoopDoSources0 + 235
17 CoreFoundation 0x01fd630e __CFRunLoopRun + 910
18 CoreFoundation 0x01fd5b33 CFRunLoopRunSpecific + 467
19 CoreFoundation 0x01fd594b CFRunLoopRunInMode + 123
20 GraphicsServices 0x032239d7 GSEventRunModal + 192
21 GraphicsServices 0x032237fe GSEventRun + 104
22 UIKit 0x00b2694b UIApplicationMain + 1225
23 ReverseHD 0x0000244d main + 141
24 libdyld.dylib 0x02975725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException