澳门银河网上官方赌场_老品牌值得信赖

ITKeyword,专注技术干货聚合推荐

注册 | 登录

node.js - Realtime video conversion using nodejs and ffmpeg

itPublisher 分享于

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址https://www.aliyun.com/minisite/goods

I'm trying to create very simple server-side video conversion using ffmpeg and nodejs. So far, I have 2 UDP servers, one for converting video input and second one for listening for converted video and passing it to websocket.

I've created one UDP server, where stream comes, converts the video input by calling ffmpeg. Then the second UDP server get the converted video and pass it to the websocket server to stream video to browser.

The problem is probably with input into the ffmpeg. The error I get is

_stream_readable.js:476
  dest.on('unpipe', onunpipe);
       ^
TypeError: Object 

The code looks like this:

// 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);


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。

澳门银河网上官方赌场