【问题标题】:How Can I delay the stream to UIImageview using AVCaptureVideoPreviewLayer from camera?如何使用来自相机的 AVCaptureVideoPreviewLayer 将流延迟到 UIImageview?
【发布时间】:2012-11-12 20:28:18
【问题描述】:

如何使用相机的 AVCaptureVideoPreviewLayer 将流延迟到 UIImageview?

请看下面我是如何绑定它们的,但我就是想不通如何延迟它(我不想要实时)

AVCaptureVideoPreviewLayer* captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

captureVideoPreviewLayer.frame = self.imageView.bounds;
[self.imageView.layer addSublayer:captureVideoPreviewLayer];

【问题讨论】:

    标签: iphone ios xcode ipad cocoa-touch


    【解决方案1】:

    首先,您需要删除您现在拥有的预览图层框架,因为没有任何方法可以延迟这些预览框架。

    您将要创建一个缓冲区。如果我们谈论的是几帧,你可以有一个 NSMutableArray,你在一端用 UIImages 填充它,同时你从另一端提供你的图像视图。

    您的 UIImage 将来自 didOutputSampleBuffer 方法,使用类似UIImage created from CMSampleBufferRef not displayed in UIImageView?

    现在,您将不得不应对几个挑战:

    • 您说的是有几秒钟的延迟,5 秒钟大约是 150 帧。在内存中存储 150 个 UIImage 是不可能的,除非它们非常小并且在最新的设备上
    • 您可以通过将图像保存到磁盘并让您的阵列只存储这些图像的路径而不是图像本身来解决这个问题。现在你可能会遇到性能问题,因为你要实时进行读/写操作,你的帧率会受到影响
    • 由于帧速率不佳,您必须确保录制的提要和实时提要之间没有失去同步,否则您会以 5 秒的延迟开始并以更长的延迟结束

    祝你好运,它可以通过一些权衡来完成(较慢的帧速率......)但它可以完成。 (我自己做过很多次非常相似的事情,由于IP原因不能分享代码)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-09
      • 1970-01-01
      相关资源
      最近更新 更多