-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathmpeg1muxer.js
58 lines (52 loc) · 1.34 KB
/
mpeg1muxer.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
var Mpeg1Muxer, child_process, events, util
child_process = require('child_process')
util = require('util')
events = require('events')
Mpeg1Muxer = function(options) {
var key
this.url = options.url
this.ffmpegOptions = options.ffmpegOptions
this.exitCode = undefined
this.additionalFlags = []
if (this.ffmpegOptions) {
for (key in this.ffmpegOptions) {
this.additionalFlags.push(key)
if (String(this.ffmpegOptions[key]) !== '') {
this.additionalFlags.push(String(this.ffmpegOptions[key]))
}
}
}
this.spawnOptions = [
"-rtsp_transport",
"tcp",
"-i",
this.url,
'-f',
'mpegts',
'-codec:v',
'mpeg1video',
// additional ffmpeg options go here
...this.additionalFlags,
'-'
]
this.stream = child_process.spawn(options.ffmpegPath, this.spawnOptions, {
detached: false
})
this.inputStreamStarted = true
this.stream.stdout.on('data', (data) => {
return this.emit('mpeg1data', data)
})
this.stream.stderr.on('data', (data) => {
return this.emit('ffmpegStderr', data)
})
this.stream.on('exit', (code, signal) => {
if (code === 1) {
console.error('RTSP stream exited with error')
this.exitCode = 1
return this.emit('exitWithError')
}
})
return this
}
util.inherits(Mpeg1Muxer, events.EventEmitter)
module.exports = Mpeg1Muxer