概述
我想使用自定义视频源通过 WebRTC Android 实现来直播视频。如果我理解正确,现有的实现仅支持 Android 手机上的前置和后置摄像头。在这种情况下,以下类是相关的:
目前,为了在 Android 手机上使用前置摄像头,我正在执行以下步骤:
CameraEnumerator enumerator = new Camera1Enumerator(false);
VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null);
VideoSource videoSource = peerConnectionFactory.createVideoSource(false);
videoCapturer.initialize(surfaceTextureHelper, this.getApplicationContext(), videoSource.getCapturerObserver());
VideoTrack localVideoTrack = peerConnectionFactory.createVideoTrack(VideoTrackID, videoSource);
我的场景
我有一个回调处理程序,它从自定义视频源接收字节数组中的视频缓冲区:
public void onReceive(byte[] videoBuffer, int size) {}
我怎样才能发送这个字节数组缓冲区?我不确定解决方案,但我想我必须实现自定义
VideoCapturer
?现有问题
This question可能是相关的,虽然我没有使用 libjingle 库,只有 native WebRTC Android 包。
类似的问题/文章:
最佳答案
这个问题有两种可能的解决方案:
VideoCapturer
并创建 VideoFrame
使用 byte[]
onReceive
中的流数据处理程序。确实有一个很好的例子FileVideoCapturer , 实现 VideoCapturer
. VideoFrame
来自 NV21Buffer ,它是从我们的字节数组流数据创建的。那么我们只需要使用我们之前创建的VideoSource
捕捉这一帧。示例:public void onReceive(byte[] videoBuffer, int size, int width, int height) {
long timestampNS = TimeUnit.MILLISECONDS.toNanos(SystemClock.elapsedRealtime());
NV21Buffer buffer = new NV21Buffer(videoBuffer, width, height, null);
VideoFrame videoFrame = new VideoFrame(buffer, 0, timestampNS);
videoSource.getCapturerObserver().onFrameCaptured(videoFrame);
videoFrame.release();
}
关于java - Android 上 WebRTC 的自定义视频源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61160558/