# hls-motion-detect

> Motion detection based on Apple HTTP Live Stream

Latest version **1.0.3** (published 2018-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install hls-motion-detect
pnpm add hls-motion-detect
yarn add hls-motion-detect
bun add hls-motion-detect
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-01-03 |
| First published | 2017-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | tan-tan |
| Maintainers | tan-tan |
| Keywords | node.js, motion, detect, hls, video |

## Links

- npm: https://www.npmjs.com/package/hls-motion-detect
- Repository: https://github.com/tan-tan-kanarek/hls-motion-detect
- Homepage: https://github.com/tan-tan-kanarek/hls-motion-detect#readme
- Issues: https://github.com/tan-tan-kanarek/hls-motion-detect/issues
- npm.io page: https://npm.io/package/hls-motion-detect

## Dependencies (7)

- [tmp](https://npm.io/package/tmp.md) 0.0.33
- [express](https://npm.io/package/express.md) ^4.15.3
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.0
- [tortoise](https://npm.io/package/tortoise.md) ^1.0.1
- [socket.io](https://npm.io/package/socket.io.md) ^2.0.1
- [dateformat](https://npm.io/package/dateformat.md) ^2.0.0
- [kaltura-client](https://npm.io/package/kaltura-client.md) ^1.0.6

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-01-03
- 1.0.2 — 2018-01-03
- 1.0.1 — 2017-06-07
- 1.0.0 — 2017-05-29

## README

# Motion Detection Server
Watch Apple HTTP Live Stream (HLS) and record to disc mp4 files containing the captured motions.


## Usage

```javascript
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:
```javascript
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*
```javascript
{
	"systemName": "test",
	"name": "test",
	"sourceURL": "http://myLiveServer/live/myStream/index.m3u8"
}
```

*http://localhost:1337/source/delete*
```javascript
{
	"systemName": "test"
}
```

*http://localhost:1337/source/start*
```javascript
{
	"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*
```javascript
{
	"systemName": "test"
}
```


### Web UI
You can controll the detect server using web UI:
```javascript
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:
```javascript
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.
```javascript
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

---
_Source: https://npm.io/package/hls-motion-detect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
