【发布时间】:2012-12-11 17:35:14
【问题描述】:
在 linux 上使用 Motion,每个网络摄像头都在其自己的端口上作为流提供。 我现在想使用 Node.js 在同一个端口上提供这些流。
- 编辑:此解决方案现在有效。我需要从原始 mjpeg 流(在我的 Motion 配置中为“BoundaryString”)获取边界字符串
app.get('/motion', function(req, res) {
var boundary = "BoundaryString";
var options = {
// host to forward to
host: '192.168.1.2',
// port to forward to
port: 8302,
// path to forward to
path: '/',
// request method
method: 'GET',
// headers to send
headers: req.headers
};
var creq = http.request(options, function(cres) {
res.setHeader('Content-Type', 'multipart/x-mixed-replace;boundary="' + boundary + '"');
res.setHeader('Connection', 'close');
res.setHeader('Pragma', 'no-cache');
res.setHeader('Cache-Control', 'no-cache, private');
res.setHeader('Expires', 0);
res.setHeader('Max-Age', 0);
// wait for data
cres.on('data', function(chunk){
res.write(chunk);
});
cres.on('close', function(){
// closed, let's end client request as well
res.writeHead(cres.statusCode);
res.end();
});
}).on('error', function(e) {
// we got an error, return 500 error to client and log error
console.log(e.message);
res.writeHead(500);
res.end();
});
creq.end();
});
我认为这会将 192.168.1.2:8302 处的 mjpeg 流作为 /motion 提供,但事实并非如此。 也许是因为它永远不会结束,而且这个代理示例并不是真正的流式示例?
【问题讨论】:
-
你可以考虑改用 nginx。
-
需要是节点解决方案
标签: node.js proxy motion mjpeg