forked from illuspas/Node-Media-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_relay_session.js
59 lines (48 loc) · 1.56 KB
/
node_relay_session.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// 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 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;
}
run() {
let argv = ['-fflags', 'nobuffer', '-analyzeduration', '1000000', '-i', this.conf.inPath, '-c', 'copy', '-f', 'flv', 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('SIGKILL');
}
}
module.exports = NodeRelaySession;