您的位置:首页 > Web前端 > Node.js

详解nodejs 使用ffmpeg获取电脑摄像头数据进行rtsp推流

2018-01-23 17:55 351 查看

nodejs 使用fluent-ffmpeg获取电脑摄像头数据进行推流

安装fluent-ffmpeg

npm install  fluent-ffmpeg


设置ffmpeg路径

FFMPEG_PATH 加入环境变量中
或者使用Ffmpeg.setFfmpegPath(path)


使用案例

var outputh = 'rtsp://' + 'ip' + ':' + 'port' + '/' + textname;
var ffmpegPath = "./ffmpeg_bin/ffmpeg.exe";
var ffmpeg = require('fluent-ffmpeg');
command = new ffmpeg('video=HD USB Camera')
.setFfmpegPath(ffmpegPath)
.inputOptions('-f dshow')
.size('800x600')
.on('start', function(commandLine) {
console.log("start push......." + commandLine);
console.log("start command......." + command);
})
.on('end', function() {
console.log("storp push........")
stopPush();
})
.on('error', function(err, stdout, stderr) {
console.log('error:' + err.message);
console.log('stdout:' + stdout);
console.log('stderr:' + stderr);
stopPush();
})
.addOptions([
// '-preset veryfast',
'-rtsp_transport tcp',
'-f rtsp'
])
.pipe(outputh, { end: true });`


停止推流

根据说明使用kill函数。但是我测试的无效,会报错

所以使用不优雅的方式直接使用child_process进行杀掉进程

var child_process = require('child_process');
var chile = child_process.exec('"taskkill" /F /IM ffmpeg.exe* /T', function(error, stdout, stderr) {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ffmpeg rtsp
相关文章推荐