Node.js 浏览器中未显示Nodewebrtc视频流
我的目标是使用gstreamer管道和WebRTC在浏览器中显示视频。 我发现它使用了node.js服务器。 我首先修改了其中一个示例(视频合成),以显示来自videotestsrc的gstreamer管道的视频。 以下是(在我看来)这方面的两个重要文件: server.jsNode.js 浏览器中未显示Nodewebrtc视频流,node.js,video-streaming,webrtc,gstreamer,Node.js,Video Streaming,Webrtc,Gstreamer,我的目标是使用gstreamer管道和WebRTC在浏览器中显示视频。 我发现它使用了node.js服务器。 我首先修改了其中一个示例(视频合成),以显示来自videotestsrc的gstreamer管道的视频。 以下是(在我看来)这方面的两个重要文件: server.js 'use strict'; const gstreamer = require("gstreamer-superficial"); const { RTCVideoSource } = require
'use strict';
const gstreamer = require("gstreamer-superficial");
const { RTCVideoSource } = require('wrtc').nonstandard;
const pipeline = new gstreamer.Pipeline("videotestsrc is-live=True ! videoconvert ! videoscale ! clockoverlay shaded-background=true ! video/x-raw,format=I420,width=1920,height=1080,framerate=25/1 ! appsink name=sink");
const appsink = pipeline.findChild('sink');
const source = new RTCVideoSource();
const track = source.createTrack();
peerConnection.addTransceiver(track);
const frame = {
width: 1920,
height: 1080,
data: null
};
var pull = function() {
appsink.pull(function(buf, caps) {
if (caps) {
console.log("CAPS", caps);
}
if (buf) {
// console.log("BUFFER size",buf.length);
frame.data = new Uint8Array(buf);
try {
source.onFrame(frame);
console.log("ON FRAME");
console.log(source);
} catch (e) {console.log(e)}
pull();
} else {
setTimeout(pull, 500);
}
});
};
pipeline.play();
pull();
// NOTE(mroberts): This is a hack so that we can get a callback when the
// RTCPeerConnection is closed. In the future, we can subscribe to
// "connectionstatechange" events.
const { close } = peerConnection;
peerConnection.close = function() {
track.stop();
return close.apply(this, arguments);
};
}
module.exports = { beforeOffer };
client.js
'use strict';
const createExample = require('../../lib/browser/example');
const description = 'This example uses node-webrtc’s RTCVideoSource and \
gstreamer-superficial to stream a video though a GStreamer pipeline.';
const remoteVideo = document.createElement('video');
remoteVideo.autoplay = true;
// remoteVideo.width = 1920;
// remoteVideo.height = 1080;
async function beforeAnswer(peerConnection) {
const remoteStream = new MediaStream(peerConnection.getReceivers().map(receiver => receiver.track));
console.log(remoteStream);
remoteVideo.srcObject = remoteStream;
console.warn(remoteVideo.srcObject);
// NOTE(mroberts): This is a hack so that we can get a callback when the
// RTCPeerConnection is closed. In the future, we can subscribe to
// "connectionstatechange" events.
const { close } = peerConnection;
peerConnection.close = function() {
remoteVideo.srcObject = null;
return close.apply(this, arguments);
};
}
createExample('video-compositing', description, { beforeAnswer });
/* const videos = document.createElement('div');
videos.className = 'grid';
videos.appendChild(remoteVideo);
document.body.appendChild(videos); */
document.body.appendChild(remoteVideo);
在服务器的控制台中,我得到了一个看起来相当不错的输出,但是在浏览器中什么都不会显示。
我不知道管道是否有问题,或者我哪里做错了什么
我用了chrome://webrtc-internals/
在webRTC上检查一点,但这对我也没有帮助。但我仍然包括了在那里给我看的东西。也许“事件”丢失了
如果我仔细看一下收信机,莫尔补充道。它向我展示了以下内容。发送方跟踪和流下是否为空可能是一个问题
有人能帮我吗?提前谢谢