-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmuxer.js
42 lines (33 loc) · 1.08 KB
/
muxer.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
var muxer;
var child_process = require('child_process');
var events = require('events');
var util = require('util');
muxer = function(options){
//console.log(options);
var self;
self = this;
this.url = options.url;
this.rate = options.rate | 10;
this.quality = (options.quality === undefined || options.quality === "") ? 3 : options.quality;
this.stream = child_process.spawn("ffmpeg", ['-loglevel', 'quiet','-i', this.url, '-r', self.rate.toString(),'-q:v',this.quality.toString(),'-f', 'image2'
, '-updatefirst', '1'
, '-'], {
detached: false
});
this.inputStreamStarted = true;
this.stream.stdout.on('data', function(data) {
//console.log("yyyy");
return self.emit('data', data.toString('base64'));
});
this.stream.stderr.on('data', function(data) {
//console.log("xxx");
return self.emit('ffmpegError', data);
});
return this;
};
muxer.prototype.abort = function(){
//console.log("request to abort");
this.stream.kill('SIGINT');
}
util.inherits(muxer, events.EventEmitter);
module.exports = muxer;