我正在尝试使用Node.js流。我的目标是接收包含以下内容的远程文件 将视频数据导入Node.js,然后将其重新路由到网页...然后可以由Internet上的第三方查看。视频的远程文件将由GStreamer生成。
远程文件在GStreamer中使用以下“管道”命令:
gst-launch videotestsrc ! x264enc ! souphttpclientsink location=<put the server location here>
上面的这一行执行必要的编码/打包,并使用PUT请求发送到指定的服务器。
我最初编写代码的尝试如下:
服务器:
var express = require('express');
var app = express();
var fs = require('fs');
var io = require("socket.io"); //web socket external module
var ioc = require('socket.io-client');
var ss = require('socket.io-stream');
var stream = ss.createStream();
io.sockets.on('connection', function (socket, username) {
// When the username is received it’s stored as a session variable
//and the 'data' is streamed to the client...
socket.on('new_client', function(username) {
username = ent.encode(username);
socket.username = username;
//send-re-route data that is being PUT onto server (from GStreamer)
fs.createReadStream('data').pipe(stream);
});
});
app.put('/', (err, res) => {
var data = [];
req.on('data', function(chunk) {
data.push(chunk);
}).on('end', function() {
//at this point data is an array of Buffers
//so Buffer.concat() can make us a new Buffer
//of all of them together
var buffer = Buffer.concat(data);
console.log(buffer.toString('base64'));
});
}); //handle the INCOMING "PUT" request (i.e. the GStreamer "Soup" file)
HTML:
<!DOCTYPE html>
<html>
<script src="/socket.io/socket.io.js"></script>
<script src="/js/socket.io-stream.js"></script>
<p> Video Stream Test </p>
<body>
<script>
// Connecting to socket.io
var socket = io.connect('http://localhost:8080');
// The username is requested, sent to the server and displayed in the title
var username = prompt('What\'s your username?');
socket.emit('new_client', username);
document.title = username + ' - ' + document.title;
<video width="640" height="480" controls>
<source src="http://localhost:8080" type="video/webm" codecs="vp8.0">
Your browser does not support the video tag.
</video>
</script>
</body>
</html>
我正在寻求社区专家的帮助,他们可以就我的身份提供指导 我写的代码做错了。由于这是我的第一次尝试,因此我的代码更适合视为原理图。
我不知道代码(如我编写的)是否会按预期执行以从PUT请求中“读取”数据,然后 重新路由到HTML页面。
很可能看到,我对在PUT请求中接收数据并对其进行流传输/重新路由感到困惑。此外,我完全不确定如何配置HTML以正确接收/显示视频文件。我故意没有在HTML中放置“发射”,因为我只是想显示接收到的内容,因此我认为没有必要。任何建议都将受到欢迎。我提前谢谢你。