How to custom WebRTC video source?

断了今生、忘了曾经 提交于 2020-06-23 06:02:06

问题


Does someone know how to change WebRTC (https://cocoapods.org/pods/libjingle_peerconnection) video source?

I am working on an screen sharing app. At the moment, I retrieve the rendered frames in real-time in CVPixelBuffer. Does someone know how I could add my frames as video source please? Is it possible to set an other video source instead of camera device source ? Is yes, which format the video has to be and how to do it ?

Thanks.


回答1:


var connectionFactory :  RTCPeerConnectionFactory = RTCPeerConnectionFactory()
let videoSource :  RTCVideoSource = factory.videoSource()
videoSource.capturer(videoCapturer, didCapture: videoFrame!)



回答2:


Mounis answer is wrong. This leads to nothing. At least not at the time of this writing. There is simply nothing happening.

In fact, you would need to satisfy this delegate

- (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFrame *)frame;

(Note the difference to the Swift version: didCapture vs. didCaptureVideoFrame)

Since this delegate is for unclear reasons not available at Swift level (the compiler says you have to use didCapture, since it has been renamed from didCaptureVideoFrame with Swift3) you have to put the code int an ObjC class. I did copy this and this (which is a part of this sample project)into my project, made my videoCapturer an instance of ARDBroadcastSampleHandler

self.videoCapturer = ARDExternalSampleCapturer(delegate: videoSource)

and within the capture callback I'm calling it

let capturer = self.videoCapturer as? ARDExternalSampleCapturer
capturer?.didCapture(sampleBuffer)


来源:https://stackoverflow.com/questions/49493923/how-to-custom-webrtc-video-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!