我想利用以下示例接受多个摄像头并流入客户端网页。
这里参考我的gstreamer命令:
gst-launch-1.0 -ve \ videotestsrc is-live = true! video / x-raw,width = 640,width = 480,framerate = 10/1!时间延迟!排队!视频转换! vaapih264enc! h264parse!排队! matroskamux streamable = true! queue leaky = 2! tcpserversink port = 9001 host = 127.0.0.1 recover-policy = keyframe sync-method = latest-keyframe \ videotestsrc is-live = true! video / x-raw,width = 640,width = 480,framerate = 10/1!时间延迟!排队!视频转换! vaapih264enc! h264parse!排队! matroskamux streamable = true! queue leaky = 2! tcpserversink port = 9002 host = 127.0.0.1 recover-policy = keyframe sync-method = latest-keyframe \
两台摄像机流向端口9001和9002.
大部分工作都发生在app.get()函数中。如何修改它以处理多个套接字。
var express = require('express')
var app = express();
var http = require('http')
var httpServer = http.createServer(app);
app.get('/', function (req, res) {
var date = new Date();
res.writeHead(200, {
'Date': date.toUTCString(),
'Connection': 'close',
'Cache-Control': 'private',
'Content-Type': 'video/webm',
//'Content-Type': video/x-matroska,
'Server': 'CustomStreamer/0.0.1',
});
var net = require('net');
var socket = net.connect(9001, function () {
socket.on('close', function (had_error) {
res.end();
});
socket.on('data', function (data) {
res.write(data);
});
});
socket.on('error', function (error) {
console.log(error);
});
});
console.log("Server listening on port.... 8001");
httpServer.listen(8001);
谢谢!
更新:创建了另一个套接字,我能够从两个不同的套接字中获取数据。可能有一个更聪明的方法来做到这一点,但是现在我重复套接字代码,将它们命名为socket1和socket2,并使用print语句我感到有信心我从两个摄像头抓取数据。现在我需要将视频链接到我的.html文件。
var socket1 = net.connect(9001, function () {
socket1.on('close', function (had_error) {
res.end();
});
socket1.on('data', function (data) {
res.write(data);
});
});
var socket2 = net.connect(9001, function () {
socket2.on('close', function (had_error) {
res.end();
});
socket2.on('data', function (data) {
res.write(data);
});
});
socket1.on('error', function (error) {
console.log(error);
});
socket2.on('error', function (error) {
console.log(error);
});