3

我正在尝试使用 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);
4

0 回答 0