是否可以在 Swift 中将 UIView 的内容/上下文作为直接视频流进行流式传输?我并不是真的在寻找“查看屏幕截图”功能,而不是组装视频,这个解决方案是可能的,但帧率远非理想。 更新:也许使用 OpenGL View ?
最佳答案
<强>1。查看截图:您目前的定时功能解决方案是什么?
我相信如果您使用CADisplayLink,您可以获得更好的帧速率。在我的项目中,我可以在 iPhone 7Plus 上以全屏视频 View 获得约 15-20fps 的直播。
<强>2。使用ReplayKit:我认为我不需要以另一种方式重写介绍,因为Apple的文档非常清晰。
Record or stream video from the screen, and audio from the app and microphone.
Using the ReplayKit framework, users can record video from the screen, and audio from the app and microphone. They can then share their recordings with other users through email, messages, and social media. You can build app extensions for live broadcasting your content to sharing services. ReplayKit is incompatible with AVPlayer content.
帧率比 View 截图高很多,但目前仅支持捕获整个屏幕。
因此,如果您想实现仅捕获 View ,可以考虑这样:裁剪输出 CMSampleBufferRef 帧的缓冲区数组。
编辑:如果是将 View 镜像到外部屏幕,那么我们可以使用 ReplayKit 或查看屏幕截图之外的其他解决方案。
关于ios - 将 UIView 输出为视频流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46953896/