Skip to content

Commit

Permalink
Formatting cleanup, refactoring, and general housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunoo authored Jul 24, 2020
1 parent fb64fdf commit 4fa5282
Show file tree
Hide file tree
Showing 15 changed files with 1,090 additions and 1,956 deletions.
40 changes: 29 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
project: './tsconfig.json'
},
rules: {
'@typescript-eslint/array-type': [
'error',
{ default: 'generic' }
],
'@typescript-eslint/camelcase': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-this-alias': ['off'],
},
'@typescript-eslint/array-type': ['error', {default: 'generic'}],
'@typescript-eslint/brace-style': 'error',
'@typescript-eslint/comma-spacing': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/func-call-spacing': 'error',
'@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/lines-between-class-members': ['error', {"exceptAfterSingleLine": true}],
'@typescript-eslint/no-base-to-string': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-extra-parens': 'error',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': ['error', {"allowComparingNullableBooleansToTrue": false, "allowComparingNullableBooleansToFalse": false}],
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/quotes': ['error', 'single', {"allowTemplateLiterals": false}],
'@typescript-eslint/semi': ['error'],
'@typescript-eslint/space-before-function-paren': ['error', 'never'],
'@typescript-eslint/type-annotation-spacing': 'error',
'comma-dangle': 'error',
'no-confusing-arrow': 'error',
'no-lonely-if': 'error',
'no-trailing-spaces': 'error',
'no-unneeded-ternary': 'error',
'one-var': ['error', 'never']
}
}
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github: Sunoo
ko_fi: sunookitsune
liberapay: Sunoo
custom: ["https://paypal.me/sunoo"]
5 changes: 5 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"default": true,
"line_length": false,
"no-duplicate-heading": false
}
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log

All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/).
All notable changes to this project will be documented in this file.

## v2.4.0 (2020-07-24)

### Changes

- Major rework of code to make future maintenance easier.
- Added setting to limit HTTP server to listening on localhost only.

## v2.3.2 (2020-07-19)

Expand Down
199 changes: 95 additions & 104 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,72 @@
<span align="center">
# Homebridge Camera FFmpeg

<a href="https://github.com/homebridge/verified/blob/master/verified-plugins.json"><img alt="homebridge-verified" src="https://github.com/homebridge/branding/blob/master/logos/homebridge-color-round.svg?sanitize=true" width="140px"></a>
[![npm](https://badgen.net/npm/v/homebridge-camera-ffmpeg) ![npm](https://badgen.net/npm/dt/homebridge-camera-ffmpeg)](https://www.npmjs.com/package/homebridge-camera-ffmpeg) [![verified-by-homebridge](https://badgen.net/badge/homebridge/verified/purple)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins)

# Homebridge Camera FFmpeg
[Homebridge](https://homebridge.io) Plugin Providing [FFmpeg](https://www.ffmpeg.org)-based Camera Support

<a href="https://www.npmjs.com/package/homebridge-camera-ffmpeg"><img title="npm version" src="https://badgen.net/npm/v/homebridge-camera-ffmpeg" ></a>
<a href="https://www.npmjs.com/package/homebridge-camera-ffmpeg"><img title="npm downloads" src="https://badgen.net/npm/dt/homebridge-camera-ffmpeg" ></a>
## Installation

<p><a href="https://www.ffmpeg.org">FFmpeg</a> plugin for
<a href="https://homebridge.io">Homebridge</a>.
</p>
Before installing this plugin, you should install Homebridge using the [official instructions](https://github.com/homebridge/homebridge/wiki).

</span>
### Install via Homebridge Config UI X

## Installation
1. Search for `Camera FFmpeg` on the Plugins tab of [Config UI X](https://www.npmjs.com/package/homebridge-config-ui-x).
2. Install the `Homebridge Camera FFmpeg` plugin and use the form to enter your camera configurations.

Basic Installation:
### Manual Installation

1. Install this plugin using: `npm install -g --unsafe-perm homebridge-camera-ffmpeg`
2. Edit `config.json` and add the camera.
1. Install this plugin using: `sudo npm install -g homebridge-camera-ffmpeg --unsafe-perm`.
2. Edit `config.json` manually to add your cameras. See below for instructions on that.

Install via Homebridge Config UI X:
## Tested configurations

1. Search for `Camera FFmpeg` on the plugin screen of the [Homebridge UI](https://github.com/oznu/homebridge-config-ui-x).
2. Install the `homebridge-camera-ffmpeg` and use the form to enter your camera settings.
Other users have been sharing configurations that work for them in [our wiki](https://github.com/Sunoo/homebridge-camera-ffmpeg/wiki/Tested-Configurations). You may want to check that to see if anyone else has gotten your model of camera working already, or to share a configuration setup that works for you.

After paring and restarting Homebridge, each camera you defined will be automatically added into the Home app.
## Manual Configuration

- To Pair Homebridge:
1. Open the Home <img src="https://user-images.githubusercontent.com/3979615/78010622-4ea1d380-738e-11ea-8a17-e6a465eeec35.png" height="16.42px"> app on your device.
2. Tap the Home tab, then tap <img src="https://user-images.githubusercontent.com/3979615/78010869-9aed1380-738e-11ea-9644-9f46b3633026.png" height="16.42px">.
3. Tap _Add Accessory_, and select _I Don't Have a Code or Cannot Scan_.
4. Select Homebridge, this will display as a bridge.
5. Enter the Homebridge PIN, this can be found under the QR code in Homebridge UI or your Homebridge logs, alternatively you can select _Use Camera_ and scan the QR code again.
6. Your cameras will then be automatically added to HomeKit.
- For help and examples of common configurations please read the wiki.
### Most Important Parameters

## Configuration
- `platform`: _(Required)_ Must always be set to `Config-ffmpeg`.
- `name`: _(Required)_ Set the camera name for display in the Home app.
- `source`: _(Required)_ FFmpeg options on where to find and how to decode your camera's video stream. The most basic form is `-i` followed by your camera's URL.
- `stillImageSource`: If your camera also provides a URL for a still image, that can be defined here with the same syntax as `source`. If not set, the plugin will grab one frame from `source`.

#### Config.json Example
#### Config Example

```json
{
"platform": "Camera-ffmpeg",
"cameras": [
{
"platform": "Camera-ffmpeg",
"cameras": [
{
"name": "Camera Name",
"videoConfig": {
"source": "-i rtsp://myfancy_rtsp_stream",
"stillImageSource": "-i http://faster_still_image_grab_url/this_is_optional.jpg",
"maxStreams": 2,
"maxWidth": 1280,
"maxHeight": 720,
"maxFPS": 30
}
}
]
"name": "Camera Name",
"videoConfig": {
"source": "-i rtsp://myfancy_rtsp_stream",
"stillImageSource": "-i http://faster_still_image_grab_url/this_is_optional.jpg",
"maxStreams": 2,
"maxWidth": 1280,
"maxHeight": 720,
"maxFPS": 30
}
}
]
}
```

#### Optional Parameters
### Optional Parameters

- `motion` enable a dummy switch and motion sensor to trigger picture notifications in iOS 13, defaults to `false`. See wiki for more detailed instructions.
- `doorbell` enable doorbell function for this camera (image notifications). When enabled there will be an additional switch that triggers the doorbell event, automate it to use it with other HomeKit switches, HTTP events etc.
- `manufacturer` set manufacturer name for display in the Home app
- `model` set model for display in the Home app
- `serialNumber` set serial number for display in the Home app
- `firmwareRevision` set firmware revision for display in the Home app
- `motion`: Exposes the motion sensor for this camera. This can be triggered with the dummy switches, MQTT messages, or via HTTP, depending on what features are enabled in the config. (Default: `false`)
- `doorbell`: Exposes the doorbell device for this camera. This can be triggered with the dummy switches, MQTT messages, or via HTTP, depending on what features are enabled in the config. (Default: `false`)
- `doorbellSwitch`: Exposes the stateless switch representing the doorbell button for this camera. (Default: `false`)
- `switches`: Enables dummy switches to trigger motion and/or doorbell, if either of those are enabled. When enabled there will be an additional switch that triggers the motion or doorbell event. See wiki for [more detailed instructions](https://github.com/Sunoo/homebridge-camera-ffmpeg/wiki/iOS-13-and-Photo-Notifications). (Default: `false`)
- `motionTimeout`: The number of seconds after triggering to reset the motion sensor. Set to 0 to disable resetting of motion trigger for MQTT or HTTP. (Default: `1`)
- `manufacturer`: Set the manufacturer name for display in the Home app. (Default: `Homebridge`)
- `model`: Set the model for display in the Home app. (Default: `Camera FFmpeg`)
- `serialNumber`: Set the serial number for display in the Home app. (Default: `SerialNumber`)
- `firmwareRevision`: Set the firmware revision for display in the Home app. (Default: current plugin version)

Example with manufacturer, model, serial number and firmware set:
#### Config Example with Manufacturer and Model Set

```
```json
{
"platform": "Camera-ffmpeg",
"cameras": [
Expand All @@ -91,30 +89,29 @@ Example with manufacturer, model, serial number and firmware set:
}
```

#### Optional videoConfig Parameters

- `maxStreams` is the maximum number of streams that will be generated for this camera, default 2
- `maxWidth` is the maximum width reported to HomeKit, default `1280`
- `maxHeight` is the maximum height reported to HomeKit, default `720`
- `maxFPS` is the maximum frame rate of the stream, default `10`
- `minBitrate` is the minimum bit rate of the stream in kbit/s, default `0`
- `maxBitrate` is the maximum bit rate of the stream in kbit/s, default `300`
- `preserveRatio` can be set to either `W` or `H` with respective obvious meanings, all other values have no effect
- `vcodec` If you're running on a RPi with the omx version of ffmpeg installed, you can change to the hardware accelerated video codec with this option, default `libx264`
- `audio` can be set to true to enable audio streaming from camera, default `false`.
- `acodec` Default audio codec is `libfdk_aac` and is enabled in the bundled ffmpeg version.
- `packetSize` If audio or video is choppy try a smaller value, set to a multiple of 188, default `1316`
- `vflip` Flips the stream vertically, default `false`
- `hflip` Flips the stream horizontally, default `false`
- `mapvideo` Select the stream used for video, default `0:0`
- `mapaudio` Select the stream used for audio, default `0:1`
- `videoFilter` Allows a custom video filter to be passed to FFmpeg via `-vf`, defaults to `scale=1280:720`
- `additionalCommandline` Allows additional of extra command line options to FFmpeg, for example `'-loglevel verbose'`
- `debug` Show the output of ffmpeg in the log, default `false`

A somewhat complicated example:

```
### Optional videoConfig Parameters

- `maxStreams`: The maximum number of streams that will be allowed concurrently this camera. (Default: `2`)
- `maxWidth`: The maximum width used for video streamed to HomeKit. If not set, will use any size HomeKit requests.
- `maxHeight`: The maximum height used for video streamed to HomeKit. If not set, will use any size HomeKit requests.
- `maxFPS`: The maximum frame rate used for video streamed to HomeKit. If not set, will use any frame rate HomeKit requests.
- `minBitrate`: The minimum bitrate used for video streamed to HomeKit, in kbit/s. If set, it will override the bitrate requested by HomeKit if that is lower than this value.
- `maxBitrate`: The maximum bitrate used for video streamed to HomeKit, in kbit/s. If not set, will use any bitrate HomeKit requests.
- `preserveRatio`: Can be set to preserve the aspect ratio based on either `W`idth or `H`eight. If not set, aspect ratio is not preserved.
- `vcodec`: Set the codec used for encoding video sent to HomeKit, must be h.264-based. If you're running on a Raspberry Pi, you can change to the hardware accelerated video codec with this option. (Default: `libx264`)
- `audio`: Enables audio streaming from camera. (Default: `false`)
- `packetSize`: If audio or video is choppy try a smaller value, should be set to a multiple of 188. (Default: `1316`)
- `vflip`: Flips the video vertically. (Default: `false`)
- `hflip`: Flips the video horizontally. (Default: `false`)
- `mapvideo`: Selects the stream used for video. (Default: `0:0`)
- `mapaudio`: Selects the stream used for audio. (Default: `0:1`)
- `videoFilter`: Allows a custom video filter to be passed to FFmpeg via `-vf`.
- `additionalCommandline` Additional extra command line options passed to FFmpeg. (Default: `-preset ultrafast -tune zerolatency`)
- `debug`: Includes debugging output from FFmpeg in the Homebridge log. (Default: `false`)

#### More Complicated Example

```json
{
"platform": "Camera-ffmpeg",
"cameras": [
Expand All @@ -140,50 +137,44 @@ A somewhat complicated example:
}
```

#### Using another Video Processor
### Automation Parameters

- `videoProcessor` is the video processor used to manage videos. eg: ffmpeg (by default) or avconv or /a/path/to/another/ffmpeg. Need to use the same parameters than ffmpeg.
- `mqtt`: Defines the hostname or IP of the MQTT broker to connect to for MQTT-based automation. If not set, MQTT support is not started. See the wiki for [more information on using MQTT](https://github.com/Sunoo/homebridge-camera-ffmpeg/wiki/MQTT-Motion).
- `portmqtt`: The port of the MQTT broker. (Default: `1883`)
- `usermqtt`: The username used to connect to your MQTT broker. If not set, no authentication is used.
- `passmqtt`: The password used to connect to your MQTT broker. If not set, no authentication is used.
- `topic`: The base MQTT topic to subscribe to. (Default: `homebridge`)
- `porthttp`: The port to listen on for HTTP-based automation. If not set, HTTP support is not started. See the wiki for [more information on using HTTP](https://github.com/Sunoo/homebridge-camera-ffmpeg/wiki/HTTP-Motion).
- `localhttp`: Only allow HTTP calls from localhost. Useful if using helper plugins that translate to HTTP. (Default: `false`)

```
{
"platform": "Camera-ffmpeg",
"videoProcessor": "avconv",
"cameras": [
...
]
}
```
#### Automation Example

```
```json
{
"platform": "Camera-ffmpeg",
"videoProcessor": "/my/own/compiled/ffmpeg",
"cameras": [
...
]
"mqtt": "127.0.0.1",
"topic": "homebridge",
"porthttp": "8080",
"cameras": []
}
```

#### Setting a source interface, or IP address
### Rarely Needed Parameters

- `interfaceName` selects the IP address of a given network interface. The default is to select the first available, and that may not be the same IP address that ffmpeg will use. A mismatch will cause the iOS device to discard the video stream.
- `videoProcessor`: Defines which video processor is used to decode and encode videos, must take the same parameters as FFmpeg. Common uses would be `avconv` or the path to a custom-compiled version of FFmpeg. If not set, will use the included version of FFmpeg, or the version of FFmpeg installed on the system if no included version is available.
- `interfaceName`: Selects which network interface to use for video streaming to HomeKit. If you have multiple active network interfaces in your system, you may need to set this. If not set, the first available network interface is used, and a mismatch will cause HomeKit to discard the video stream.

```
#### Rare Option Example

```json
{
"platform": "Camera-ffmpeg",
"interfaceName": "bond0",
"cameras": [
...
]
"videoProcessor": "/usr/bin/ffmpeg",
"interfaceName": "eth0",
"cameras": []
}
```

## Tested configurations

We have started collecting tested configurations in the wiki, so please before raising an issue with your configuration, please check the [wiki](https://github.com/homebridge-plugins/homebridge-camera-ffmpeg/wiki). Also if you have a working configuration that you would like to share, please add it to the [wiki](https://github.com/homebridge-plugins/homebridge-camera-ffmpeg/wiki).

https://github.com/homebridge-plugins/homebridge-camera-ffmpeg/wiki

## Credit

Homebridge Camera FFmpeg was originally created by [Khaos Tian](https://twitter.com/khaost).
Homebridge Camera FFmpeg is based on code originally written by [Khaos Tian](https://twitter.com/khaost).
Loading

0 comments on commit 4fa5282

Please sign in to comment.