image: add stream experimental property with server-side ffmpeg backend (#259)
This commit is contained in:
parent
e41024f5f4
commit
dfdac01bf3
4 changed files with 56 additions and 1 deletions
|
|
@ -59,7 +59,37 @@ var bindCallbacks = function(callbacks) {
|
|||
|
||||
}
|
||||
|
||||
// video streams
|
||||
|
||||
var rtsp = require('rtsp-ffmpeg'),
|
||||
urls = settings.read('videoStreams'),
|
||||
streams = {},
|
||||
framerate = 10,
|
||||
resolution = undefined
|
||||
|
||||
for (var i in urls) {
|
||||
if (/framerate\s*=\s*[0-9]+/.test(urls[i])) {
|
||||
framerate = Math.max(Math.min(parseInt(urls[i].split('=').pop()), 60), 0)
|
||||
}
|
||||
if (/resolution\s*=\s*[0-9]+x[0-9]+/.test(urls[i])) {
|
||||
resolution = urls[i].split('=').pop().trim()
|
||||
}
|
||||
}
|
||||
|
||||
urls = urls.filter(item => item.indexOf('rtsp://') > -1)
|
||||
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
streams[i] = new rtsp.FFMpeg({
|
||||
input: urls[i],
|
||||
rate: framerate,
|
||||
resolution: resolution,
|
||||
})
|
||||
streams[i].on('data', (data)=>{
|
||||
ipc.send('video', [i, data.toString('base64')])
|
||||
})
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
console.log('App available at ' + appAddresses.join(' & '))
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ var options = {
|
|||
true : 'examples can\'t be listed if --load is set'
|
||||
}
|
||||
},
|
||||
'video-streams':{type:'array',describe:'video stream urls (rtsp://)'},
|
||||
'url-options':{type:'array',describe:'url options (opt=value pairs)',
|
||||
check: (u, argv)=>{
|
||||
return (!u || !argv.n) ?
|
||||
|
|
@ -120,6 +121,7 @@ var makeDefaultConfig = function(argv){
|
|||
sessionFile: argv.l || false,
|
||||
newSession: argv.b || false,
|
||||
customModule: argv.c || false,
|
||||
videoStreams: argv['video-streams'] || [],
|
||||
fullScreen: argv['fullscreen'] || false,
|
||||
noGui: argv.n || false,
|
||||
guiOnly: typeof argv.g == 'string' ? argv.g.length ? argv.g : true : false,
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
"nanomorph": "^5.1.3",
|
||||
"node-sass": "4.7.2",
|
||||
"nodemon": "1.17.2",
|
||||
"rtsp-ffmpeg": "0.0.12",
|
||||
"scope-css": "^1.0.5",
|
||||
"screenfull": "3.3.2",
|
||||
"shortid": "2.2.8",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
var {mapToScale} = require('../utils'),
|
||||
Widget = require('../common/widget')
|
||||
Widget = require('../common/widget'),
|
||||
ipc = require('../../ipc')
|
||||
|
||||
module.exports = class Led extends Widget {
|
||||
|
||||
|
|
@ -30,6 +31,7 @@ module.exports = class Led extends Widget {
|
|||
repeat: 'no-repeat',
|
||||
border: true,
|
||||
cache: true,
|
||||
stream: '',
|
||||
|
||||
_value: 'value',
|
||||
default: '',
|
||||
|
|
@ -58,6 +60,10 @@ module.exports = class Led extends Widget {
|
|||
this.widget.style.setProperty('background-position', this.getProp('position'))
|
||||
this.widget.style.setProperty('background-repeat', this.getProp('repeat'))
|
||||
|
||||
if (this.getProp('stream') !== '') {
|
||||
this.bindedOnStreamUpdate = this.onStreamUpdate.bind(this)
|
||||
ipc.on('video', this.bindedOnStreamUpdate)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -89,4 +95,20 @@ module.exports = class Led extends Widget {
|
|||
|
||||
}
|
||||
|
||||
onStreamUpdate(event) {
|
||||
console.log(event)
|
||||
var [stream, data] = event
|
||||
if (stream === this.getProp('stream')) {
|
||||
this.setValue('data:image/jpeg;base64,' + data)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onRemove() {
|
||||
|
||||
if (this.bindedOnStreamUpdate) ipc.off('video', this.bindedOnStreamUpdate)
|
||||
super.onRemove()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue