1.0.3 • Published 7 years ago

hls-motion-detect v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Motion Detection Server

Watch Apple HTTP Live Stream (HLS) and record to disc mp4 files containing the captured motions.

Usage

const motion = require('hls-motion-detect');

let detectServer = new motion.DetectServer({
	ffmpegPath: 'ffmpeg', 
	ffprobePath: 'ffprobe', 
	recordingsPath: './recorded'
})
.listen(1336)
.on('source-added', (source) => {
	console.log(`New Source added [${source.systemName}] URL [${source.sourceURL}]`);
	
	source
	.on('start', (filepath) => {
		console.log(`Source [${source.systemName}] started`);
	})
	.on('stop', () => {
		console.log(`Source [${source.systemName}] stopped`);
	})
	.on('record-start', (filepath) => {
		console.log(`Source [${source.systemName}] started recording: ${filepath}`);
	})
	.on('record-stop', (filepath) => {
		console.log(`Source [${source.systemName}] stopped recording`);
	});
})
.on('source-removed', (systemName) => {
	console.log(`Source removed [${systemName}]`);
});

REST API

You can controll the detect server using REST API:

let apiServer = new motion.ApiServer(detectServer)
.listen(1337)
.on('listen', (port) => {
	console.log(`REST API server running at port ${port}`);
}).
on('debug', (msg) => {
	console.log(msg);
}).
on('error', (msg) => {
	console.error(msg);
});

API enables add, delete, start and stop.

http://localhost:1337/source/add

{
	"systemName": "test",
	"name": "test",
	"sourceURL": "http://myLiveServer/live/myStream/index.m3u8"
}

http://localhost:1337/source/delete

{
	"systemName": "test"
}

http://localhost:1337/source/start

{
	"systemName": "test",
	"interval": 3, // in seconds, if not specified default is one second.
	"x": 100, // not supported yet, defaults to 0.
	"y": 100, // not supported yet, defaults to 0.
	"width": 100, // not supported yet, defaults to 0.
	"height": 100, // not supported yet, defaults to 0.
	"threshold": 30, // (between 1 and 50) defaults to 35, use higher value to increase sensitivity and lower value to decrease sensitivity.
	"maxIdleTime": 60 // time to wait since last segment detected to raise idle event (Used by RabbitMQ to remove the source).
}

http://localhost:1337/source/stop

{
	"systemName": "test"
}

Web UI

You can controll the detect server using web UI:

let webServer = new motion.WebServer(detectServer)
.listen({
	port: 3888,
	path: './lib/plugins/web-server/web', // you can change that static path to your own web folder
})
.on('listen', (port) => {
	console.log(`Web server running at port ${port}`);
});

RabbitMQ Messages

You add sources through RabbitMQ:

let rabbitServer = new motion.RabbitServer(detectServer)
.on('listen', () => {
	console.log('Rabbit-MQ server running');
}).
on('error', (msg) => {
	console.error(msg);
})
.listen({
//	auth: 'guest:guest',
	host: 'localhost',
//	port: 5672,
	queue: 'stream-queue'
});

RabbitMQ plugins supports only adding new source, once the source is idle it will be removed automatically.

Kaltura Integration

Kaltura plugin will automatically upload recorded files to your Kaltura account.

let kaltura = new Kaltura(detectServer, {
	partnerId: 123, // replace with your Kaltura account id
	secret: 'your secret here'
})
.on('error', (msg) => {
	console.error(msg);
})
.on('entry-created', (entry) => {
	console.log(`New entry [${entry.id}] uploaded`);
});

Tools

To test Rabbit-MQ message, use utils/addRabbitMessage.js