I want to change the order of movie frames and then write them back to new video file. It would be much easier for me to have them all in array, but process of coping buffer samples to array causes crash on real device ( but it’s OK in simulator). All I can see in Xcode is message: „Lost connection to DEVICE_NAME” in the middle of this process - no crash logs, etc.
So let’s start with something what doesn’t cause any problems: printing timestamp of each frame
CMSampleBufferRef sample;
while(sample = [readerOutput copyNextSampleBuffer]) {
CMTime timestamp = CMSampleBufferGetPresentationTimeStamp((__bridge CMSampleBufferRef)(__bridge id)sample);
NSLog(@"%f", (float)timestamp.value / timestamp.timescale);
CFRelease(sample);
}
But when I try to copy sample buffers to array this way:
NSMutableArray *samples = [[NSMutableArray alloc] init];
CMSampleBufferRef sample;
while(sample = [readerOutput copyNextSampleBuffer]) {
[samples addObject:(__bridge id)sample];
CMSampleBufferInvalidate(sample);
CFRelease(sample);
sample = NULL;
}
or this way
CFMutableArrayRef frameArray = CFArrayCreateMutable(NULL, 1000, &kCFTypeArrayCallBacks);
sample = [readerOutput copyNextSampleBuffer];
while (sample != NULL) {
sample = [readerOutput copyNextSampleBuffer];
if (sample != NULL) {
CFArrayAppendValue(frameArray, sample);
}
CFRelease(sample);
}
it crashes. Am I try to do something impossible ?