简体   繁体   English

将CMSampleBufferRef处理为数组会导致崩溃

[英]Coping CMSampleBufferRef to array causes crash

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. 我在Xcode中看到的只有一条消息:在此过程的中间,“到DEVICE_NAME的连接断开”-没有崩溃日志等。

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 ? 我会尝试做一些不可能的事情吗?

您可以将其转换为UIImage,然后添加到数组,但是,使用时需要将其转换回CMSampleBufferRef,这可能会导致一点时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM