0%

frigate 动态检测

frigate 安装后我只启动了动态检测,因为我的家用服务器上没有显卡,所以没有开启AI检测功能。

USB 摄像头转 rtsp

我用的 usb摄像头进行测试,因为 frigate 需要 rtsp 视频流所以需要进行一下转换。
转换我用的 go2rtc 进行转换。
go2rtc 创建 go2rtc.yaml 配置文件并写入以下内容。

1
2
3
4
streams:
# 查看设备 v4l2-ctl --list-devices 一般选择物理设备的第0个挂载接口
# 查看摄像头支持的分辨率 v4l2-ctl -d /dev/video0 --list-formats-ext
linux_usbcam: ffmpeg:device?video=0&video_size=1920x1080#video=h264

启动 go2rtc 使用 ./go2rtc -c go2rtc.yaml 命令进行启动,然后就可以通过 http://<你的服务器地址>:1984/ 访问 ui 面板了,在这里你可以检查你的摄像头

frigate 安装

frigate 安装我使用的 docker compose,因为我看了,官方的 dockerfile 感觉挺复杂,所以使用官方推荐的 docker 方式进行安装。

compose.yaml 文件内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
services:
frigate:
container_name: frigate
restart: unless-stopped
stop_grace_period: 30s
image: ghcr.io/blakeblackshear/frigate:stable
shm_size: "512mb" # 默认 64mb 启动会有警告信息,可以不用管
volumes:
- ./config:/config
- ./storage:/media/frigate
- type: tmpfs # 可选:1GB内存,减少SSD/SD卡损耗
target: /tmp/cache
tmpfs:
size: 1000000000
ports:
- "8971:8971"
- "8554:8554"

配置好后,使用 mkdir storage config 创建数据目录,注意不可配置 user 运行用户,直接用默认的 root 就行。
都创建好后使用 docker compose up -d 启动既可。
启动后使用 docker logs frigate 寻找默认的用户名和密码。
找到后可以使用 https://192.168.10.105:8971/ 访问webui。这时候你有可能遇到 webui显示不完全的问题,别担心,接着往下看,在 config 里关闭 ssl 后就可以正常显示了。
使用 docker compose down 停止程序后继续配置。
修改 config/config.yaml 到以下内容。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
mqtt:
enabled: false

tls: # 不关闭的话,使用代理访问ui显示不完全
enabled: false

cameras:
name_of_your_camera: # <------ Name the camera
enabled: true
ffmpeg:
inputs:
- path: rtsp://<运行go2rtc转换usb到rtsp机器的ip>:8554/linux_usbcam?mp4 # <----- camera 地址
roles: # 检测模式
#- detect
- record
detect: # ai 检测
enabled: false # <---- disable detection until you have a working camera feed
width: 1920
height: 1080
record: # 动态检测录像
enabled: true
retain:
days: 3
mode: motion
alerts:
retain:
days: 30
mode: motion
detections:
retain:
days: 30
mode: motion

运行 docker compose up -d 启动后,就可以在 webui上看到你的摄像头

注意事项

我的摄像头没有夜间模式,也就是晚上什么都看不见。在这种情况下会一直检测到动态,然后一直在录像,看资料可以调节检测强度解决。