Create a WebRTC VideoTrack with a “custom” Capturer on Android with libjingle

空扰寡人 提交于 2019-12-03 15:29:54

问题


How to use a "custom" video capturer to create a VideoTrack and provide frames?

The classic approach to create a VideoTrack is:

1 - Get a VideoCapturer instance

VideoCapturer capturer = VideoCapturer.create(name);

2 - Create a VideoSource

VideoSource videoSource = peerconnectionFactory.createVideoSource(capturer, videoConstraints);

3 - Create a VideoTrack using the video source

VideoTrack videoTrack = peerconnectionFactory.createVideoTrack("Label", videoSource);

4 - Add the track to the MediaStream


I was wondering if there is a way to change step one. Instead of using the native Capturer instance, use an Android one, and provide the frames to the VideoTrack using the callback:

public void onPreviewFrame(byte[] data, Camera camera) {
   // provide the frames to the VideoTrack
}

Any suggestions?


回答1:


The easiest way (although a bit "hacky") to do this is to copy the source of RTCVideoCapturer to a local class withing your project and just use that local class. You can now edit the class to suit your needs. Even when not copying the file but actually building your own, it's probably better to copy large parts of the existing capturer than to reinvent the wheel.



来源:https://stackoverflow.com/questions/23654425/create-a-webrtc-videotrack-with-a-custom-capturer-on-android-with-libjingle

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