forked from illuspas/Node-Media-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_fission_session.js
57 lines (48 loc) · 1.71 KB
/
node_fission_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
//
// 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;