我正在尝试使用ffmpeg和nodejs创建非常简单的服务器端视频转换。 到目前为止,我有2台UDP服务器,一台用于转换视频输入,另一台用于监听转换后的视频并将其传递给websocket。
我创建了一个UDP服务器,其中流来了,通过调用ffmpeg转换视频输入。然后第二个UDP服务器获取转换后的视频并将其传递给websocket服务器,以将视频流式传输到浏览器。
问题可能在于输入ffmpeg。我得到的错误是
_stream_readable.js:476
dest.on('unpipe', onunpipe);
^
TypeError: Object
代码如下所示:
// Websocket Server
var socketServer = new (require('ws').Server)({port: 8081});
socketServer.on('connection', function(socket) {
socket.on('close', function(code, message){
console.log( 'Disconnected WebSocket ('+socketServer.clients.length+' total)' );
});
});
socketServer.broadcast = function(data, opts) {
for( var i in this.clients ) {
this.clients[i].send(data, opts);
}
};
// UDP Server
var udpServer = require("dgram").createSocket("udp4");
udpServer.on("message", function(msg, rinfo) {
socketServer.broadcast(msg, {binary:true});
console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port);
});
udpServer.on("listening", function() {
var address = udpServer.address();
console.log("server listening " + address.address + ":" + address.port);
});
udpServer.bind(8082);
// UDP Server for stream conversion
var udpServer2 = require("dgram").createSocket("udp4");
udpServer2.on("message", function(msg, rinfo) {
// ********** THIS IS WHERE ERROR OCCURS **************
var ffmpeg = require('child_process')
.spawn('ffmpeg',['-f','video4linux2','-i','-','-f','mpeg1video','udp://127.0.0.1:8082']);
ffmpeg.stdin.pipe(msg);
});
udpServer2.on("listening", function() {
var address = udpServer2.address();
console.log("server listening " + address.address + ":" + address.port);
});
udpServer2.bind(8083);