在浏览器中播放原始 h264 直播流

Kir*_*Raj 14 html javascript live-streaming http-live-streaming webrtc

我正在寻找一种解决方案,通过 WebSocket 在浏览器上实时播放来自本机服务器的原始 h264 流。我在 JavaScript 中尝试了许多第三方 h264 解码器,每个都有自己的问题。基于 Broadway 的解码器无法解码 main 和 high profile h264。其他解码器太慢而无法解码 1080p 帧。我尝试在 JavaScript 中将原始 h264 转换为碎片化的 mp4,但是在解码双向帧时播放非常难看。我也尝试过 webrtc,但似乎不可能在浏览器和本机服务器之间实现对等连接。有什么建议?

Bar*_*n01 11

我见过的最好的(我自己没有使用它的实践经验)是https://github.com/samirkumardas/jmuxer

https://github.com/samirkumardas/jmuxer/blob/master/example/index-h264.html 上有一个如何通过 WebSockets 处理流数据的示例

var socketURL = 'ws://localhost:8080';
var jmuxer = new JMuxer({
    node: 'player',
    mode: 'video',
    flushingTime: 1000,
    fps: 30,
    debug: true
});
var ws = new WebSocket(socketURL);
ws.binaryType = 'arraybuffer';
ws.addEventListener('message',function(event) {
     jmuxer.feed({
         video: new Uint8Array(event.data)
     });
});
ws.addEventListener('error', function(e) {
    console.log('Socket Error');
});
Run Code Online (Sandbox Code Playgroud)