RTCMultiConnection 可以使用 H264 而不是 VP9 进行屏幕共享吗?

Can RTCMultiConnection use H264 instead of VP9 for screenshare?

我正在从事与屏幕共享相关的项目,我遇到的唯一问题是需要显示从 PC 或 Mac(Chromium 浏览器,实际上是 Electron 应用程序)共享的屏幕,在 Raspberry PI 上(我使用的是最现代的型号 3 B)。在我的实验中,项目才刚刚开始,我正在使用 RTCMultiConnection 共享屏幕并观看它。

问题是,即使在显示它的 Chromium 中启用了完整的硬件加速,它也毫无用处地慢(2-3 fps,有时会有 10 秒的延迟),我完全理解为什么:因为它使用 VP9 编解码器,因为Raspberry 上不存在硬件加速。

问题是:我可以在 RTCMultiConnection 中使用 H264 吗?如果是,如何?我知道WebRTC本身基本支持。

在您的 HTML 演示文件中添加以下代码:

connection.processSdp = function(sdp) {
    // remove VP8+VP9 so that Firefox can use H264
    sdp = CodecsHandler.removeVPX(sdp);
    return sdp;
};

转到 "dev" 目录并打开此文件:dev/CodecsHandler.js#L5-L30 第 5 到 30 行。

确保 VP8 和 VP9 线正确。

a=rtpmap:100
a=rtpmap:101

可能 VP8 是 96,VP9 是 98。因此相应地替换 rtpmap。例如

a=rtpmap:96
a=rtpmap:98

确保仅使用 Firefox 进行测试。我不知道 Chrome 稳定频道是否也支持 H264。

Fireox 可能需要一些标志。您可以在 about:config

上搜索 h264 标志

确保 link dev/CodecsHandler.js 在您的 HTML 演示文件中,紧跟在 dist/RTCMultiConnection.min.js 之后。

<script src="dist/RTCMultiConnection.min.js"></script>
<script src="dev/CodecsHandler.js"></script>
<script>
var connection = new RTCMultiConnection();
connection.socketURL = 'https://yourserver.com:9001/';
connection.processSdp = function(sdp) {
    // remove VP8+VP9 so that Firefox can use H264
    sdp = CodecsHandler.removeVPX(sdp);
    return sdp;
};
connection.openOrJoin('roomid');
</script>