目前我正在使用AVFoundation
从 iPhone 相机中抓取帧然后将它们转换为UIImage
然后我将它传输到NSOutputStream
我将它发送到我的其他设备。
不幸的是,我很可能因内存过多而崩溃,因为它一度达到 300mb。
我的问题:有没有更好的方法来做到这一点或其他一些方法可以使它停止崩溃或在我发送图像和在另一台设备上获取图像之间有更少的延迟?或者我可以让它像一个生命流,它几乎就像接收设备上的一个视频?
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
@autoreleasepool {
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
[_room broadcastChatMessage:image fromUser:@"self"];
dispatch_async(dispatch_get_main_queue(), ^(void){
[_imgView setImage:image];
});
}
// < Add your code here that uses the image >
}