【问题标题】:How to modify (add filters to) the camera stream that WebRTC is sending to other peers/server如何修改(添加过滤器)WebRTC 发送到其他对等点/服务器的摄像头流
【发布时间】:2016-12-08 11:25:30
【问题描述】:

范围

我正在使用 RTCCameraPreviewView 显示本地摄像头流

    let videoSource = self.pcFactory.avFoundationVideoSource(with: nil)
    let videoTrack = self.pcFactory.videoTrack(with: sVideoSource, trackId: "video0")

    //setting the capture session to my RTCCameraPreviewView:
    (self.previewView as! RTCCameraPreviewView).captureSession = (videoTrack.source as! RTCAVFoundationVideoSource).captureSession

    stream = self.pcFactory.mediaStream(withStreamId: "unique_label")
    audioTrack = self.pcFactory.audioTrack(withTrackId: "audio0")
    stream.addAudioTrack(audioTrack)

    var device: AVCaptureDevice?
    for captureDevice in AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) {
        if (captureDevice as AnyObject).position == AVCaptureDevicePosition.front {
            device = captureDevice as? AVCaptureDevice
            break
        }
    }
    if device != nil && videoTrack != nil {
        stream.addVideoTrack(videoTrack)
    }

    configuration = RTCConfiguration()

    configuration.iceServers = iceServers
    peerConnection = self.pcFactory.peerConnection(with: configuration, constraints: RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: ["DtlsSrtpKeyAgreement": "true"]), delegate: self)
    peerConnection.add(stream)

一切都按预期进行。

问题

现在我想从相机中获取帧并对它们进行预处理以添加一些过滤器(棕褐色、黑白等),然后将帧中继到 WebRTC。在浏览了 webrtc 文档之后,我仍然无法找到从哪里开始以及该做什么。

任何形式的提醒都将受到高度赞赏!

【问题讨论】:

标签: ios iphone swift webrtc apprtcdemo


【解决方案1】:

我找到了一条出路。因此,基本上您需要构建自己的 WebRTC pod,然后您可以添加一个挂钩,以便在 videoOutput 对象上使用自定义 AVCaptureVideoDataOutputSampleBufferDelegate。然后处理sampleBuffer,修改buffer再传给webrtc。

实施

打开文件 webrtc/sdk/objc/Frameworks/Classes/RTCAVFoundationVideoCapturerInternal.mm

就行了:

[videoDataOutput setSampleBufferDelegate:self queue:self.frameQueue];

使用自定义委托而不是 self。

在那个委托中

  class YourDelegate : AVCaptureVideoDataOutputSampleBufferDelegate {
 func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
        let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)

        //modify the pixelBuffer
        //get the modifiedSampleBuffer from modified pixelBuffer
        DispatchQueue.main.async {
            //show the modified buffer to the user
        }

        //To pass the modified buffer to webrtc (warning: [this is objc code]):
        //(_capturer object is found in RTCAVFoundationVideoCapturerInternal.mm)
        _capturer->CaptureSampleBuffer(modifiedSampleBuffer, _rotation);

    }
}

【讨论】:

  • 嗨,你可以创建一些 pod 供下载吗?我很难为 webrtc 创建自己的 pod
  • 对不起,伙计。我不能。我的机器上不再有 iOS 开发设置。
猜你喜欢
  • 2019-01-25
  • 1970-01-01
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
  • 1970-01-01
  • 1970-01-01
  • 2013-06-28
相关资源
最近更新 更多