5 Star 35 Fork 13

nygula / Node-Media-Server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
node_fission_session.js 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
Chen Mingliang 提交于 2020-07-16 23:18 . f
//
// Created by Chen Mingliang on 20/7/16.
// illuspas[a]msn.com
// Copyright (c) 2020 Nodemedia. All rights reserved.
//
const Logger = require('./node_core_logger');
const EventEmitter = require('events');
const { spawn } = require('child_process');
const dateFormat = require('dateformat');
const mkdirp = require('mkdirp');
const fs = require('fs');
class NodeFissionSession extends EventEmitter {
constructor(conf) {
super();
this.conf = conf;
}
run() {
let inPath = 'rtmp://127.0.0.1:' + this.conf.rtmpPort + this.conf.streamPath;
let argv = ['-i', inPath];
for (let m of this.conf.model) {
let x264 = ['-c:v', 'libx264', '-preset', 'veryfast', '-tune', 'zerolatency', '-maxrate', m.vb, '-bufsize', m.vb, '-g', parseInt(m.vf) * 2, '-r', m.vf, '-s', m.vs];
let aac = ['-c:a', 'aac', '-b:a', m.ab];
let outPath = ['-f', 'flv', 'rtmp://127.0.0.1:' + this.conf.rtmpPort + '/' + this.conf.streamApp + '/' + this.conf.streamName + '_' + m.vs.split('x')[1]];
argv.splice(argv.length, 0, ...x264)
argv.splice(argv.length, 0, ...aac)
argv.splice(argv.length, 0, ...outPath)
}
argv = argv.filter((n) => { return n });
this.ffmpeg_exec = spawn(this.conf.ffmpeg, argv);
this.ffmpeg_exec.on('error', (e) => {
Logger.ffdebug(e);
});
this.ffmpeg_exec.stdout.on('data', (data) => {
Logger.ffdebug(`FF输出:${data}`);
});
this.ffmpeg_exec.stderr.on('data', (data) => {
Logger.ffdebug(`FF输出:${data}`);
});
this.ffmpeg_exec.on('close', (code) => {
Logger.log('[Fission end] ' + this.conf.streamPath);
this.emit('end');
});
}
end() {
this.ffmpeg_exec.kill();
}
}
module.exports = NodeFissionSession;
1
https://gitee.com/nygula/Node-Media-Server.git
git@gitee.com:nygula/Node-Media-Server.git
nygula
Node-Media-Server
Node-Media-Server
master

搜索帮助