Cambiar QNAP Survillance Station por Frigate

Después de cambiar el TVS-882 por un TVS-h674 resulta que de pronto la licencia para ocho cámaras de Survillance Station que tenia no me servia , y ahora me ofrecían los muy cachondos una licencia para un nuevo servicio llamado QVR Elite para dos cámaras y el resto a pasar por caja mensualmente , QNAP me estas tocando las bolas y lo peor es que no es con tu hardware , si no con la política a lo Netflix que tienes , mal vamos ehhhhhh…

A todo esto tengo en casa Motioneye que me va de p…. madre , pero quería buscar alguna alternativa , esta alternativa la encontre en Frigate , toda la documentación la podéis encontrar aquí

Lo primero será crear las carpetas para que el docker funcione correctamente

Crearemos un fichero de configuracion en /config/config.yml con la configuración mínima para que arranque

mqtt:
  enabled: False

cameras:
  dummy_camera: # <--- this will be changed to your actual camera later
    enabled: False
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:554/rtsp
          roles:
            - detect

Para instalarlo en un NAS QNAP estas serian las instrucciones

QNAP NAS

These instructions were tested on a QNAP with an Intel J3455 CPU and 16G RAM, running QTS 4.5.4.2117.

QNAP has a graphic tool named Container Station to install and manage docker containers. However, there are two limitations with Container Station that make it unsuitable to install Frigate:

  1. Container Station does not incorporate GitHub Container Registry (ghcr), which hosts Frigate docker image version 0.12.0 and above.
  2. Container Station uses default 64 Mb shared memory size (shm-size), and does not have a mechanism to adjust it. Frigate requires a larger shm-size to be able to work properly with more than two high resolution cameras.

Because of above limitations, the installation has to be done from command line. Here are the steps:

Preparation

  1. Install Container Station from QNAP App Center if it is not installed.
  2. Enable ssh on your QNAP (please do an Internet search on how to do this).
  3. Prepare Frigate config file, name it config.yml.
  4. Calculate shared memory size according to documentation.
  5. Find your time zone value from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  6. ssh to QNAP.

Installation

Run the following commands to install Frigate (using stable version as example):

# Download Frigate image
docker pull ghcr.io/blakeblackshear/frigate:stable
# Create directory to host Frigate config file on QNAP file system.
# E.g., you can choose to create it under /share/Container.
mkdir -p /share/Container/frigate/config
# Copy the config file prepared in step 2 into the newly created config directory.
cp path/to/your/config/file /share/Container/frigate/config
# Create directory to host Frigate media files on QNAP file system.
# (if you have a surveilliance disk, create media directory on the surveilliance disk.
# Example command assumes share_vol2 is the surveilliance drive
mkdir -p /share/share_vol2/frigate/media
# Create Frigate docker container.  Replace shm-size value with the value from preparation step 3.
# Also replace the time zone value for 'TZ' in the sample command.
# Example command will create a docker container that uses at most 2 CPUs and 4G RAM.
# You may need to add "--env=LIBVA_DRIVER_NAME=i965 \" to the following docker run command if you
# have certain CPU (e.g., J4125). See https://docs.frigate.video/configuration/hardware_acceleration.
docker run \
  --name=frigate \
  --shm-size=256m \
  --restart=unless-stopped \
  --env=TZ=America/New_York \
  --volume=/share/Container/frigate/config:/config:rw \
  --volume=/share/share_vol2/frigate/media:/media/frigate:rw \
  --network=bridge \
  --privileged \
  --workdir=/opt/frigate \
  -p 1935:1935 \
  -p 5000:5000 \
  -p 8554:8554 \
  -p 8555:8555 \
  -p 8555:8555/udp \
  --label='com.qnap.qcs.network.mode=nat' \
  --label='com.qnap.qcs.gpu=False' \
  --memory="4g" \
  --cpus="2" \
  --detach=true \
  -t \
  ghcr.io/blakeblackshear/frigate:stable

Log into QNAP, open Container Station. Frigate docker container should be listed under ‘Overview’ and running. Visit Frigate Web UI by clicking Frigate docker, and then clicking the URL shown at the top of the detail page.

Yo al final modifique la configuración para darle mas chicha al bicho y que fuera mas sobrado de recursos quedando asi :

docker run \
  --name=frigate \
  --shm-size=800m \
  --restart=always \
  --env=TZ='Europe/Madrid' \
  --volume=/share/camaras/frigate/config:/config:rw \
  --volume=/share/camaras/frigate/media:/media/frigate:rw \
  --network=bridge \
  --privileged \
  --workdir=/opt/frigate \
  -p 1935:1935 \
  -p 5100:5000 \
  -p 8554:8554 \
  -p 8555:8555 \
  -p 8555:8555/udp \
  --label='com.qnap.qcs.network.mode=nat' \
  --label='com.qnap.qcs.gpu=False' \
  --memory="6g" \
  --cpus="6" \
  --detach=true \
  ghcr.io/blakeblackshear/frigate:stable

Una vez arrancado ya podremos acceder mediante el navegador , en ese momento solo hay una cámara dummy creada , ahora toca la tarea de ir configurando todas las cámaras y las preferencias para que funcione como mejor nos vaya , desde el navegador definiremos tanto las zonas como las mascaras de cada cámara si así queremos que actué

Al final mi fichero de config.yml quedo así

mqtt:
  enabled: true
  user: xxxxxxxxxx
  password: xxxxxxxxxx
  host: xxxxxxxxxx.duckdns.org
  port: 21883
  # timestamp: true
  # bounding_box: true
  # crop: true
  # height: 500
  # quality: 100

# Optional: Detectors configuration. Defaults to a single CPU detector
# detectors:
  # # Required: name of the detector
  # detector_name:
    # # Required: type of the detector
    # # Frigate provided types include 'cpu', 'edgetpu', 'openvino' and 'tensorrt' (default: shown below)
    # # Additional detector types can also be plugged in.
    # # Detectors may require additional configuration.
    # # Refer to the Detectors configuration page for more information.
    # type: cpu

# Optional: Database configuration
database:
  # The path to store the SQLite DB (default: shown below)
  path: /config/frigate.db

# Optional: logger verbosity settings
logger:
  # Optional: Default log verbosity (default: shown below)
  default: debug
  # Optional: Component specific logger overrides
  logs:
    frigate.event: debug
    frigate.mqtt: debug
    frigate.app: debug
    frigate.object_detection: debug

timestamp_style:
  # Optional: Position of the timestamp (default: shown below)
  #           "tl" (top left), "tr" (top right), "bl" (bottom left), "br" (bottom right)
  position: tl
  # Optional: Format specifier conform to the Python package "datetime" (default: shown below)
  #           Additional Examples:
  #           german: "%d.%m.%Y %H:%M:%S"
  format: '%d/%m/%Y %H:%M:%S'
  # Optional: Color of font
  color:
    # All Required when color is specified (default: shown below)
    red: 255
    green: 255
    blue: 255
  # Optional: Line thickness of font (default: shown below)
  thickness: 2
  # Optional: Effect of lettering (default: shown below)
  #           None (No effect),
  #           "solid" (solid background in inverse color of font)
  #           "shadow" (shadow for font)
  effect: solid

motion:
  # Optional: The threshold passed to cv2.threshold to determine if a pixel is different enough to be counted as motion. (default: shown below)
  # Increasing this value will make motion detection less sensitive and decreasing it will make motion detection more sensitive.
  # The value should be between 1 and 255.
  threshold: 30
  mqtt_off_delay: 5
  lightning_threshold: 0.8

record:
  enabled: true
  retain:
    days: 7
    mode: all
  events:
    retain:
      default: 30
      mode: motion
  sync_recordings: true

snapshots:
  # Optional: Enable writing jpg snapshot to /media/frigate/clips (default: shown below)
  enabled: true
  # Optional: save a clean PNG copy of the snapshot image (default: shown below)
  clean_copy: true
  # Optional: print a timestamp on the snapshots (default: shown below)
  timestamp: true
  # Optional: draw bounding box on the snapshots (default: shown below)
  bounding_box: true
  # Optional: crop the snapshot (default: shown below)
  crop: false
  # Optional: height to resize the snapshot to (default: original size)
  # height: 175
  # Optional: Restrict snapshots to objects that entered any of the listed zones (default: no required zones)
  required_zones: []
  # Optional: Camera override for retention settings (default: global values)
  retain:
    # Required: Default retention days (default: shown below)
    default: 30
    # Optional: Per object retention days
    objects:
      person: 30
  # Optional: quality of the encoded jpeg, 0-100 (default: shown below)
  quality: 100

rtmp:
  # Optional: Enable the RTMP stream (default: False)
  enabled: false

cameras:
  # dummy_camera: # <--- this will be changed to your actual camera later
    # enabled: False
    # ffmpeg:
      # inputs:
        # - path: rtsp://127.0.0.1:554/rtsp


  # Required: name of the camera

  foscam_1:
    # Optional: Enable/Disable the camera (default: shown below).
    # If disabled: config is used but no live stream and no capture etc.
    # Events/Recordings are still viewable.
    enabled: true
    # Required: ffmpeg settings for the camera
    ffmpeg:
      # Required: A list of input streams for the camera. See documentation for more information.
      inputs:
        # Required: the path to the stream
        # NOTE: path may include environment variables or docker secrets, which must begin with 'FRIGATE_' and be referenced in {}
      - path: rtsp://xxxxxxxxxx:yyyyyyyyyyy@ZZ.ZZ.ZZ.71:88/videoMain
        roles:
        - audio
        - detect
        - record
        - rtmp

    # to be replaced by a newer image. (default: shown below)
    best_image_timeout: 60
    # Optional: URL to visit the camera web UI directly from the system page. Might not be available on every camera.
    webui_url: ''
    ui:
      order: 0
      dashboard: true

    # Optional: Configuration for how to sort the cameras in the Birdseye view.
    birdseye:
      order: 0
    motion:
      mask:
      - 1920,0,1647,320,1152,0
      - 1920,1080,970,1080,1920,0
      - 0,1080,398,1080,0,409
    zones:
      zone_patio_entrada_2:
        coordinates: 599,119,739,388,973,699,778,817,444,978,384,903,260,738,120,496,23,259
    snapshots:
      enabled: true

    mqtt:
      # Optional: Enable publishing snapshot via mqtt for camera (default: shown below)
      # NOTE: Only applies to publishing image data to MQTT via 'frigate/<camera_name>/<object_name>/snapshot'.
      # All other messages will still be published.
      enabled: true
      # Optional: print a timestamp on the snapshots (default: shown below)
      timestamp: true
      # Optional: draw bounding box on the snapshots (default: shown below)
      bounding_box: true
      # Optional: crop the snapshot (default: shown below)
      # crop: true
      # Optional: height to resize the snapshot to (default: shown below)
      # height: 270
      # Optional: jpeg encode quality (default: shown below)
      quality: 100
      # Optional: Restrict mqtt messages to objects that entered any of the listed zones (default: no required zones)
      required_zones: []


  foscam_2:
    # Optional: Enable/Disable the camera (default: shown below).
    # If disabled: config is used but no live stream and no capture etc.
    # Events/Recordings are still viewable.
    enabled: true
    # Required: ffmpeg settings for the camera
    ffmpeg:
      # Required: A list of input streams for the camera. See documentation for more information.
      inputs:
        # Required: the path to the stream
        # NOTE: path may include environment variables or docker secrets, which must begin with 'FRIGATE_' and be referenced in {}
      - path: rtsp://xxxxxxxxxx:yyyyyyyyyyy@ZZ.ZZ.ZZ.72:88/videoMain
        roles:
        - audio
        - detect
        - record
        - rtmp

    # to be replaced by a newer image. (default: shown below)
    best_image_timeout: 60
    # Optional: URL to visit the camera web UI directly from the system page. Might not be available on every camera.
    webui_url: ''
    ui:
      order: 0
      dashboard: true
    # Optional: Configuration for how to sort the cameras in the Birdseye view.
    birdseye:
      order: 0
    motion:
      mask:
      - 175,321,468,0,258,0,153,0,76,0,0,0,0,228,0,353,0,720,82,720
      - 1280,0,1280,720,782,678,771,649,754,0
      - 0,696,876,685,1161,625,1280,611,1280,686,1280,720,0,720
    zones:
      zone_entrada_calle_2:
        coordinates: 311,255,314,417,393,571,395,720,108,683,174,428
    snapshots:
      enabled: true

    mqtt:
      # Optional: Enable publishing snapshot via mqtt for camera (default: shown below)
      # NOTE: Only applies to publishing image data to MQTT via 'frigate/<camera_name>/<object_name>/snapshot'.
      # All other messages will still be published.
      enabled: true
      # Optional: print a timestamp on the snapshots (default: shown below)
      timestamp: true
      # Optional: draw bounding box on the snapshots (default: shown below)
      bounding_box: true
      # Optional: crop the snapshot (default: shown below)
      # crop: true
      # Optional: height to resize the snapshot to (default: shown below)
      # height: 270
      # Optional: jpeg encode quality (default: shown below)
      quality: 100
      # Optional: Restrict mqtt messages to objects that entered any of the listed zones (default: no required zones)
      required_zones: []


  foscam_3:
    # Optional: Enable/Disable the camera (default: shown below).
    # If disabled: config is used but no live stream and no capture etc.
    # Events/Recordings are still viewable.
    enabled: true
    # Required: ffmpeg settings for the camera
    ffmpeg:
      # Required: A list of input streams for the camera. See documentation for more information.
      inputs:
        # Required: the path to the stream
        # NOTE: path may include environment variables or docker secrets, which must begin with 'FRIGATE_' and be referenced in {}
      - path: rtsp://xxxxxxxxxx:yyyyyyyyyyy@ZZ.ZZ.ZZ.73:88/videoMain
        roles:
        - audio
        - detect
        - record
        - rtmp

    # to be replaced by a newer image. (default: shown below)
    best_image_timeout: 60
    # Optional: URL to visit the camera web UI directly from the system page. Might not be available on every camera.
    webui_url: ''
    ui:
      order: 0
      dashboard: true

    # Optional: Configuration for how to sort the cameras in the Birdseye view.
    birdseye:
      order: 0

    motion:
      mask:
      - 22,0,0,1080,455,1080,273,666,229,494,376,438,791,270,1098,134,1293,37,1497,0
    snapshots:
      enabled: true
    zones:
      zone_puerta_terraza_2:
        coordinates: 1920,133,1920,479,1700,469,1737,126

    mqtt:
      # Optional: Enable publishing snapshot via mqtt for camera (default: shown below)
      # NOTE: Only applies to publishing image data to MQTT via 'frigate/<camera_name>/<object_name>/snapshot'.
      # All other messages will still be published.
      enabled: true
      # Optional: print a timestamp on the snapshots (default: shown below)
      timestamp: true
      # Optional: draw bounding box on the snapshots (default: shown below)
      bounding_box: true
      # Optional: crop the snapshot (default: shown below)
      # crop: true
      # Optional: height to resize the snapshot to (default: shown below)
      # height: 270
      # Optional: jpeg encode quality (default: shown below)
      quality: 100
      # Optional: Restrict mqtt messages to objects that entered any of the listed zones (default: no required zones)
      required_zones: []

        
  HIKVISION_1:
    # Optional: Enable/Disable the camera (default: shown below).
    # If disabled: config is used but no live stream and no capture etc.
    # Events/Recordings are still viewable.
    enabled: true
    # Required: ffmpeg settings for the camera
    ffmpeg:
      # Required: A list of input streams for the camera. See documentation for more information.
      inputs:
        # Required: the path to the stream
        # NOTE: path may include environment variables or docker secrets, which must begin with 'FRIGATE_' and be referenced in {}
      - path: rtsp://xxxxxxxxxx:yyyyyyyyyyy@ZZ.ZZ.ZZ.155:554
        roles:
        - audio
        - detect
        - record
        - rtmp

    # to be replaced by a newer image. (default: shown below)
    best_image_timeout: 60
    # Optional: URL to visit the camera web UI directly from the system page. Might not be available on every camera.
    webui_url: ''
    ui:
      order: 0
      dashboard: true

    # Optional: Configuration for how to sort the cameras in the Birdseye view.
    birdseye:
      order: 0

    motion:
      mask:
      - 0,2160,278,2160,412,2160,287,1965,268,1915,240,1834,281,1809,318,1775,493,1684,667,1563,814,1416,1007,1226,1054,951,1734,917,2311,880,2844,870,3275,855,3634,861,3840,867,3840,552,3840,0,2735,0,2377,0,1488,0,855,0,0,0,0,767,0,1129,0,1438
    zones:
      zone_patio_entrada:
        coordinates: 1285,1715,880,2160,421,2160,218,1762,749,1538
    snapshots:
      enabled: true

    mqtt:
      # Optional: Enable publishing snapshot via mqtt for camera (default: shown below)
      # NOTE: Only applies to publishing image data to MQTT via 'frigate/<camera_name>/<object_name>/snapshot'.
      # All other messages will still be published.
      enabled: true
      # Optional: print a timestamp on the snapshots (default: shown below)
      timestamp: true
      # Optional: draw bounding box on the snapshots (default: shown below)
      bounding_box: true
      # Optional: crop the snapshot (default: shown below)
      # crop: true
      # Optional: height to resize the snapshot to (default: shown below)
      # height: 270
      # Optional: jpeg encode quality (default: shown below)
      quality: 100
      # Optional: Restrict mqtt messages to objects that entered any of the listed zones (default: no required zones)
      required_zones: []


  HIKVISION_2:
    # Optional: Enable/Disable the camera (default: shown below).
    # If disabled: config is used but no live stream and no capture etc.
    # Events/Recordings are still viewable.
    enabled: true
    # Required: ffmpeg settings for the camera
    ffmpeg:
      # Required: A list of input streams for the camera. See documentation for more information.
      inputs:
        # Required: the path to the stream
        # NOTE: path may include environment variables or docker secrets, which must begin with 'FRIGATE_' and be referenced in {}
      - path: rtsp://xxxxxxxxxx:yyyyyyyyyyy@ZZ.ZZ.ZZ.156:554
        roles:
        - audio
        - detect
        - record
        - rtmp

    # to be replaced by a newer image. (default: shown below)
    best_image_timeout: 60
    # Optional: URL to visit the camera web UI directly from the system page. Might not be available on every camera.
    webui_url: ''
    ui:
      order: 0
      dashboard: true

    # Optional: Configuration for how to sort the cameras in the Birdseye view.
    birdseye:
      order: 0
    motion:
      mask:
      - 2626,0,3543,0,3662,0,3840,0,3840,958,0,437,0,0
      - 0,2160,1076,2160,1095,1740,0,1506
    zones:
      zone_entrada_calle:
        coordinates: 2632,1394,2748,2160,1653,2160,1703,1338
    snapshots:
      enabled: true

    mqtt:
      # Optional: Enable publishing snapshot via mqtt for camera (default: shown below)
      # NOTE: Only applies to publishing image data to MQTT via 'frigate/<camera_name>/<object_name>/snapshot'.
      # All other messages will still be published.
      enabled: true
      # Optional: print a timestamp on the snapshots (default: shown below)
      timestamp: true
      # Optional: draw bounding box on the snapshots (default: shown below)
      bounding_box: true
      # Optional: crop the snapshot (default: shown below)
      # crop: true
      # Optional: height to resize the snapshot to (default: shown below)
      # height: 270
      # Optional: jpeg encode quality (default: shown below)
      quality: 100
      # Optional: Restrict mqtt messages to objects that entered any of the listed zones (default: no required zones)
      required_zones: []
  IC-3116W:
    # Optional: Enable/Disable the camera (default: shown below).
    # If disabled: config is used but no live stream and no capture etc.
    # Events/Recordings are still viewable.
    enabled: true
    # Required: ffmpeg settings for the camera
    ffmpeg:
      # Required: A list of input streams for the camera. See documentation for more information.
      inputs:
        # Required: the path to the stream
        # NOTE: path may include environment variables or docker secrets, which must begin with 'FRIGATE_' and be referenced in {}
      - path: rtsp://xxxxxxxxxx:yyyyyyyyyyy@ZZ.ZZ.ZZ.253:554/ipcam_mjpeg.sdp
        roles:
        - audio
        - detect
        - record
        - rtmp

    # to be replaced by a newer image. (default: shown below)
    best_image_timeout: 60
    # Optional: URL to visit the camera web UI directly from the system page. Might not be available on every camera.
    webui_url: ''
    ui:
      order: 0
      dashboard: true

    # Optional: Configuration for how to sort the cameras in the Birdseye view.
    birdseye:
      order: 0

    motion:
      mask:
      - 0,186,521,132,550,109,640,109,640,0,297,0,0,0
    zones:
      zone_puerta_terraza:
        coordinates: 640,188,585,412,115,397,118,158
    snapshots:
      enabled: true

    mqtt:
      # Optional: Enable publishing snapshot via mqtt for camera (default: shown below)
      # NOTE: Only applies to publishing image data to MQTT via 'frigate/<camera_name>/<object_name>/snapshot'.
      # All other messages will still be published.
      enabled: true
      # Optional: print a timestamp on the snapshots (default: shown below)
      timestamp: true
      # Optional: draw bounding box on the snapshots (default: shown below)
      bounding_box: true
      # Optional: crop the snapshot (default: shown below)
      # crop: true
      # Optional: height to resize the snapshot to (default: shown below)
      # height: 270
      # Optional: jpeg encode quality (default: shown below)
      quality: 100
      # Optional: Restrict mqtt messages to objects that entered any of the listed zones (default: no required zones)
      required_zones: []

una vez abramos el navegador accederemos a la vista principal de la cámaras donde podremos gestionarlas.

En el botón eventos veremos todos aquellos eventos que ha ido detectando el sistema

En sistema veremos la velocidad de interferencia y los frames que se tiene que saltar por no tener recursos , al principio le asigne 4 cpu’s y se saltaba algunos frames dando bastantes falsos positivos , fue asignarle 6 cpu’s y a funcionar como una seda

Este seria el consumo de recursos en el TVS-h674 , ni se inmuta ….

Una de las cosas que echo en falta respecto a motioneye es que no tiene autenticación , por eso si lo vais a abrir al exterior ( cosa que yo no haría ) , se puede solventar con la autenticación básica de Traefik

Y con esto y un bizcocho ….