1 Star 0 Fork 13

MeenJ. / Node-Media-Server

forked from nygula / Node-Media-Server 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
node_relay_session.js 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
Chen Mingliang 提交于 2020-07-16 21:11 . f
//
// Created by Mingliang Chen on 18/3/16.
// illuspas[a]gmail.com
// Copyright (c) 2018 Nodemedia. All rights reserved.
//
const Logger = require('./node_core_logger');
const NodeCoreUtils = require("./node_core_utils");
const EventEmitter = require('events');
const { spawn } = require('child_process');
const RTSP_TRANSPORT = ['udp', 'tcp', 'udp_multicast', 'http'];
class NodeRelaySession extends EventEmitter {
constructor(conf) {
super();
this.conf = conf;
this.id = NodeCoreUtils.generateNewSessionID();
this.TAG = 'relay';
}
run() {
let format = this.conf.ouPath.startsWith('rtsp://') ? 'rtsp' : 'flv';
let argv = ['-i', this.conf.inPath, '-c', 'copy', '-f', format, this.conf.ouPath];
if (this.conf.inPath[0] === '/' || this.conf.inPath[1] === ':') {
argv.unshift('-1');
argv.unshift('-stream_loop');
argv.unshift('-re');
}
if (this.conf.inPath.startsWith('rtsp://') && this.conf.rtsp_transport) {
if (RTSP_TRANSPORT.indexOf(this.conf.rtsp_transport) > -1) {
argv.unshift(this.conf.rtsp_transport);
argv.unshift('-rtsp_transport');
}
}
Logger.ffdebug(argv.toString());
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('[Relay end] id=', this.id);
this.emit('end', this.id);
});
}
end() {
this.ffmpeg_exec.kill();
}
}
module.exports = NodeRelaySession;
1
https://gitee.com/MQueenJ/Node-Media-Server.git
git@gitee.com:MQueenJ/Node-Media-Server.git
MQueenJ
Node-Media-Server
Node-Media-Server
master

搜索帮助