在浏览器中播放来自gstreamer的视频流

时间:2019-06-03 14:32:18

标签: html stream webrtc gstreamer media-source

我想在Web浏览器中播放gstreamer的流。

我在RTP,WebRTC和SDP文件中使用,但是VLC可以通过简单的SDP连接到流,而浏览器却不能。后来我了解到WebRTC需要安全的连接,这只会使事情复杂化,而就我的目的而言并不需要。我偶然发现了html5的 Media Source Extension (MSE),它似乎可以帮上忙,但是我找不到关于如何使gstreamer传输正确数据和以后如何使用MSE播放它们。我也不确定使用MSE的延迟时间。

有没有办法在浏览器中播放来自gstreamer的流? 谢谢。

1 个答案:

答案 0 :(得分:0)

使用节点webrtc project,我能够将gstreamer的输出与webrtc调用结合在一起。对于gstreamer,有一个项目可以与节点gstreamer superficial一起使用。因此,基本上,您需要从节点进程运行gstremaer进程,然后可以控制gstremaer的输出。在每个gstreamer框架上,都有一个名为的回调,该回调将框架接收并发送给webrtc调用。

然后需要实施webrtc调用。呼叫需要某种信令协议。呼叫的一侧将是服务器,另一侧将是客户端的浏览器,而不是两个浏览器。然后将创建一个视频轨道,将来自gstreamer浅表的帧推入。

const { RTCVideoSource } = require("wrtc").nonstandard;
const gstreamer = require("gstreamer-superficial");

const source = new RTCVideoSource();
// This is WebRTC video track which should be used with addTransceiver see below
const track = source.createTrack();

const frame = {
        width: 1920,
        height: 1080,
        data: null
};

const pipeline = new gstreamer.Pipeline("v4l2src ! videorate ! video/x-raw,format=YUY2,width=1920,height=1080,framerate=25/1 ! videoconvert ! video/x-raw,format=I420 ! appsink name=sink");
const appsink = pipeline.findChild("sink");
const pull = function() {
        appsink.pull(function(buf, caps) {
                if (buf) {
                        frame.data = new Uint8Array(buf);
                        try {
                                source.onFrame(frame);
                        } catch (e) {}
                        pull();
                } else if (!caps) {
                        console.log("PULL DROPPED");
                        setTimeout(pull, 500);
                }
        });
};

pipeline.play();
pull();

// Example:
const useTrack = SomeRTCPeerConnection => SomeRTCPeerConnection.addTransceiver(track, { direction: "sendonly" });