this post was submitted on 18 Nov 2023
16 points (94.4% liked)

Self-Hosted Main

502 readers
1 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

For Example

We welcome posts that include suggestions for good self-hosted alternatives to popular online services, how they are better, or how they give back control of your data. Also include hints and tips for less technical readers.

Useful Lists

founded 1 year ago
MODERATORS
 

So I've been self-hosting my CCTV for about 3 years now and it's always been... not great

First I gave Blue Iris a try which meant I needed a full Windows VM to run it

And it worked - it did the job and recorded stuff and it was fairly OK at motion detection, but damn did it eat the CPU and draw a lot of electricity for no real reason

A few months later I gave Shinobi CCTV a try in Docker and that's what I've been running since

Again, it's mostly fine but the UI is a little clunky and my use case of "24/7 recording that I can easily watch back" was mostly being met, although I had 1 problem

By default Shinobi segments video into 15 minute chunks

So if someone smashes into my car at 14:45:01 then I can't watch that footage until 15:00

Obviously this is a big flaw, so to get around this I changed the segment size to 1 minute

But I have 4 cameras, so this means that over a day I'll now have 5760 clips per day

Sifting through those to find some footage is not fun

Enter Frigate - I'd tried it before but never really gave it a full chance

It's a bit to wrap your head around at first, but once it's up and running it's just a docker-compose.yml for the container and a simple frigate.yml config file

The docs are EXTENSIVE and answered almost every question I had

But there's 1 extra awesome feature I wasn't originally aware of: OpenVINO

OpenVINO is a deep learning model from Intel that apparently runs on my old Broadwell gen Xeon E5-2650v4 CPUs without issue

I've turned it on and enabled object detection and I gotta say, WOW, it's very good

I can go outside with the dog, walk around for a moment and come back in and it'll pick both of us up no problem

So this saved me about £100 seeing as I don't need a Coral compute module (OK I could still get one, but I'm happy for now)

And just to top all of this off, Frigate and Reolink cameras generally don't play too nicely together, yet with support from the docs, mine are working great

Looking at Zabbix, my CPU utilisation for my CCTV server was averaging 10% whilst using Shinobi

Now it's up to 50% but my UPS runtime hasn't really changed so I'm calling that a win

My config is below if it helps anyone trying to get this set up with Reolink cameras


# Disable MQTT because I'm not connecting this to Home Assistant
mqtt:
  enabled: false

# Enable 24/7 recording (mode: all means all clips, not just clips with objects in)
# Keep 30 days worth of footage (Frigate automatically deletes the oldest footage once space gets extremely low)
record:
  enabled: true
  retain:
    days: 30
    mode: all

# Set the birdseye view to always show a live stream of the cameras
birdseye:
  mode: continuous

# Detection area for cameras (all 4 of my Reolink RLC-410 cameras are 2560x1920)
detect:
  width: 2560
  height: 1920

# Objects to track from /labelmap.txt
objects:
  track:
    - person
    - bicycle
    - car
    - motorcycle
    - bird
    - cat
    - dog

# Copy and paste from docs to use default OpenVINO
# https://docs.frigate.video/configuration/detectors/#openvino-detector
detectors:
  ov:
    type: openvino
    device: AUTO
    model:
      path: /openvino-model/ssdlite_mobilenet_v2.xml

model:
  width: 300
  height: 300
  input_tensor: nhwc
  input_pixel_format: bgr
  labelmap_path: /openvino-model/coco_91cl_bkgr.txt

# Config for each camera
cameras:
  c1-side:
    ffmpeg:
      inputs:
        # Record HD stream
        - path: http://10.10.8.11/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password={FRIGATE_C1_PASS}
          input_args: preset-http-reolink
          roles:
            - record
        # Use low quality and low FPS stream for object detection
        - path: http://10.10.8.11/flv?port=1935&app=bcs&stream=channel0_sub.bcs&user=admin&password={FRIGATE_C1_PASS}
          input_args: preset-http-reolink
          roles:
            - detect
      # Record audio
      output_args:
        record: preset-record-generic-audio-copy

  c2-garden:
    ffmpeg:
      inputs:
        - path: http://10.10.8.12/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password={FRIGATE_C2_PASS}
          input_args: preset-http-reolink
          roles:
            - record
        - path: http://10.10.8.12/flv?port=1935&app=bcs&stream=channel0_sub.bcs&user=admin&password={FRIGATE_C2_PASS}
          input_args: preset-http-reolink
          roles:
            - detect
      output_args:
        record: preset-record-generic-audio-copy

  c3-garage:
    ffmpeg:
      inputs:
        - path: http://10.10.8.13/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password={FRIGATE_C3_PASS}
          input_args: preset-http-reolink
          roles:
            - record
        - path: http://10.10.8.13/flv?port=1935&app=bcs&stream=channel0_sub.bcs&user=admin&password={FRIGATE_C3_PASS}
          input_args: preset-http-reolink
          roles:
            - detect
      output_args:
        record: preset-record-generic-audio-copy

  c4-front:
    ffmpeg:
      inputs:
        - path: http://10.10.8.14/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password={FRIGATE_C4_PASS}
          input_args: preset-http-reolink
          roles:
            - record
        - path: http://10.10.8.14/flv?port=1935&app=bcs&stream=channel0_sub.bcs&user=admin&password={FRIGATE_C4_PASS}
          input_args: preset-http-reolink
          roles:
            - detect
      output_args:
        record: preset-record-generic-audio-copy
top 19 comments
sorted by: hot top controversial new old
[–] sirrush7@alien.top 2 points 10 months ago

Oh this is fantastic, exactly what I will be moving to shortly! Thanks so much for sharing OP!

[–] Do_TheEvolution@alien.top 2 points 10 months ago (1 children)

Can you post the compose?

Also I thought that frigate is only usable through home assistant, but that only means android app I guess.

Anyway, I am actually in process of picking few cameras, likely going with tplink vigi, like C340 and see if it will play nicely.

[–] SpongederpSquarefap@alien.top 1 points 10 months ago

Sure thing

Also I thought that frigate is only usable through home assistant, but that only means android app I guess.

Nope, Home Assistant is just a nice integration with it

The web UI is fast and responsive - even on mobile in Chrome

You can easily view object detections and recordings by day and hour through the web UI too

It's extremely well done

Anyway, I am actually in process of picking few cameras, likely going with tplink vigi, like C340 and see if it will play nicely.

Frigate have docs on recommended cameras

https://docs.frigate.video/frigate/hardware

Regardless of what cameras you choose, please ensure you VLAN and firewall them off - these cameras effectively run a Linux distro and should not be trusted or accessible

For example, my Reolink cameras can access NTP and DNS just so their clocks are correct

They can't access anything else on the network

The CCTV VM sits on the same network as the cameras and has host firewall rules to deny access from the cameras

Frigate just connects to each camera's stream and does its magic from there


version: "3.9"
services:
  frigate:
    container_name: frigate
    privileged: true # this may not be necessary for all setups
    restart: unless-stopped
    image: ghcr.io/blakeblackshear/frigate:stable
    shm_size: "512mb" # update for your cameras based on calculation above
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /opt/dockervolumes/frigate/config/config.yml:/config/config.yml
      - /mnt/cctv/frigate:/media/frigate
      - type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear
        target: /tmp/cache
        tmpfs:
          size: 1000000000
    ports:
      - "8554:8554"     # RTSP feeds
      - "8555:8555/tcp" # WebRTC over tcp
      - "8555:8555/udp" # WebRTC over udp
    environment:
      FRIGATE_C1_PASS: ${FRIGATE_C1_PASS}
      FRIGATE_C2_PASS: ${FRIGATE_C2_PASS}
      FRIGATE_C3_PASS: ${FRIGATE_C3_PASS}
      FRIGATE_C4_PASS: ${FRIGATE_C4_PASS}
    labels:
      - traefik.enable=true
      - traefik.http.routers.cctv.rule=Host(`cctv.${DOMAIN}`)
      - traefik.http.routers.cctv.entrypoints=websecure
      - traefik.http.routers.cctv.tls.certresolver=cloudflare
      - traefik.http.services.cctv.loadbalancer.server.port=5000
    networks:
      - proxy
networks:
  proxy:
    external: true
[–] geek_at@alien.top 1 points 10 months ago

Nobody here using AgentDVR? The docker works great and has GPU and AI support and can be integrated in Homeassistant.

Only downside is that you can't use https with the free version (unless you use it via homeassistant)

[–] Eboettn@alien.top 1 points 10 months ago

RemindMe! 12 hours

[–] ndnihil@alien.top 1 points 10 months ago

Have been running my own NVR for decades, most of it with the motion project. Recently started switching things over to Frigate and I am impressed with it as well. The Corals are worth the money. I run two of them on my setup (6 to 8 1080 cams at any given time) and quite pleased with it.

The default models are great at detecting humans, but not so much cars/wildlife. I definitely plan to try and expand on that in the near future.

[–] Elle221LL@alien.top 1 points 10 months ago

"And it worked—it did the job, recorded stuff, and was fairly okay at motion detection. However, it consumed a significant amount of CPU and drew a lot of electricity for no real reason. You didn't optimize it.

For me, with 4 4k Cameras + more 1080p cameras, it uses 1.5% to 3% when nobody is viewing the cameras. Of course, it will go up if somebody is viewing the cameras, as it will need to transcode to view it on the web. I wanted to try other alternatives as well on Linux, but I still preferred Blue Iris at the end.

You can find information on optimizing Blue Iris's CPU usage in this link: Optimizing Blue Iris's CPU Usage.

https://ipcamtalk.com/wiki/optimizing-blue-iris-s-cpu-usage/

[–] bebopblues@alien.top 1 points 10 months ago (1 children)

Blue Iris user here, I heard good things about Frigate before, but like you, I never tried it because it seems hard to set up and configure. But since I also have Reolink cameras and with your docker compose.yml file, I might give it a shot.

First I gave Blue Iris a try which meant I needed a full Windows VM to run it

by the way, using wine, Blue Iris can be run in docker as well. I never tried it, but it exists.

it eat the CPU and draw a lot of electricity for no real reason

Starting with version 5, BI can use substreams for detection as well, so CPU usage is way down, like at 10-20% on my 12 year old intel i7.

[–] SpongederpSquarefap@alien.top 1 points 10 months ago

Oh wow that's a hell of an improvement

It's been about 4 years since I last used it so I'm happy to see they're still actively improving it

[–] LoPanDidNothingWrong@alien.top 1 points 10 months ago (2 children)

Yeah. I used shinobi before and Frigate is a lot better and easier to configure.

I need to figure out how to get notifications when recording fails and stuff like that.

[–] pm_something_u_love@alien.top 1 points 10 months ago (1 children)

One thing that Shinobi could do was integrate well with the detectors on cam, so if your cam had person/vehicle detection or line crossing etc you could use that. That worked well.

But I too went from Shinobi to Frigate and I love it. The integration with HA is very good.

[–] LoPanDidNothingWrong@alien.top 1 points 10 months ago

My cameras have on-camera detection I just don’t use it. I have a Coral passed through to the docker.

[–] SpongederpSquarefap@alien.top 1 points 10 months ago

Log tail with Zabbix trigger could work

[–] nickm_27@alien.top 1 points 10 months ago (3 children)

One thing to mention is that you're currently running detection on 2560x1920 but your reolink ext stream is going to be something like 896x672 so you're using cpu to scale that stream up to the higher resolution. You may find lower cpu usage by running detect at that streams specific resolution

[–] Tha_Reaper@alien.top 1 points 10 months ago

He is using the sub stream for detection according to his config right?

[–] SpongederpSquarefap@alien.top 1 points 10 months ago

Ooh that's a schoolboy error

Corrected it - should have been 640x480

[–] SpongederpSquarefap@alien.top 1 points 10 months ago

Wow, I was averaging 60% CPU before

Now the resolution is correct it's averaging 35%

[–] stoneobscurity@alien.top 0 points 10 months ago

you'll want to add a coral tpu.

[–] cryptopoes@alien.top 0 points 10 months ago

Get a Google Coral TPU for frigate