转流功能
RTSP 转流
Frigate 可以将您的视频流重新以 RTSP 协议流式转发传输,供其他应用程序(如 Home Assistant)使用,地址为rtsp://<frigate_host>:8554/<camera_name>。必须开放转发容器内8554端口。这样您就可以同时使用一个视频流进行 Frigate 检测和 Home Assistant 实时查看,而无需与摄像头建立两个独立连接。视频流将直接从原始视频流复制,避免重新编码。此流不包含 Frigate 的任何标注。
Frigate 使用go2rtc提供转流和 MSE/WebRTC 功能。go2rtc 配置位于配置文件的go2rtc部分,更多高级配置和功能请参阅go2rtc 文档。
NOTE
您可以通过/api/go2rtc/streams访问 go2rtc 流信息,这对调试很有帮助,也能提供有关摄像头流的有用信息。
鸟瞰图转流
鸟瞰图 RTSP 转流可通过rtsp://<frigate_host>:8554/birdseye访问。启用鸟瞰图转流将使鸟瞰图 24/7 运行,这可能会略微增加 CPU 使用率。
birdseye:
restream: True提示
To improve connection speed when using Birdseye via restream you can enable a small idle heartbeat by setting birdseye.idle_heartbeat_fps to a low value (e.g. 1–2). This makes Frigate periodically push the last frame even when no motion is detected, reducing initial connection latency.
使用认证保护转流
go2rtc 转流可以通过设置 RTSP 的用户名/密码认证进行保护。例如:
go2rtc:
rtsp:
username: 'admin'
password: 'pass'
streams: ...警告
即使设置了 go2rtc 的 RTSP 流权限,Frigate 内部访问自己的 go2rtc 转流的时候(也就是用rtsp://127.0.0.1:8554/摄像头名称 这类型视频流的时候),也无需提供账号密码进行鉴权。
减少摄像头连接数 强烈建议使用
某些摄像头仅支持一个视频流(即只能有一个设备可以访问摄像头)连接,亦或者你希望减少与摄像头不必要的连接数,RTSP 转流功能能很好的解决你的问题。
单流配置
与摄像头只建立一个连接,并将该摄像头视频流进行转流;然后 Frigate 的检测(detect)和录制(record)将使用该转流。
go2rtc:
streams:
name_your_rtsp_cam: # <- 你的RTSP流名称,修改为你自己希望的摄像头名称,只支持英文数字下划线和连接符
- rtsp://192.168.1.5:554/live0 # <- 摄像头原本的RTSP流示例,支持视频和AAC音频的流
- 'ffmpeg:name_your_rtsp_cam#audio=opus' # <- 将音频转码为缺失编解码器(通常是opus)的视频流副本
name_your_http_cam: # <- 其他类型的视频流,例如http,该名称为示例,请自行修改
- http://192.168.50.155/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=user&password=password # <- 摄像头原本的HTTP视频流示例,支持视频和AAC音频的流
- 'ffmpeg:name_your_http_cam#audio=opus' # <- 将音频转码为缺失编解码器(通常是opus)的视频流副本
cameras:
name_your_rtsp_cam: # <- 摄像头名称和go2rtc上的视频流名称尽可能一致
ffmpeg:
output_args:
record: preset-record-generic-audio-copy
inputs:
- path: rtsp://127.0.0.1:8554/name_your_rtsp_cam # <--- 注意!这里的名称(name_your_rtsp_cam)必须与上面转流中设置的视频流名称一致!记得修改
input_args: preset-rtsp-restream # 使用转流一定要修改为preset-rtsp-restream
roles:
- record
- detect
- audio # <- 仅在启用音频检测时需要
name_your_http_cam: # <- 第二个摄像头,摄像头名称和go2rtc上的视频流名称尽可能一致
ffmpeg:
output_args:
record: preset-record-generic-audio-copy
inputs:
- path: rtsp://127.0.0.1:8554/name_your_http_cam # <--- 注意!这里的名称(name_your_http_cam)必须与上面转流中设置的摄像头名称一致!记得修改
input_args: preset-rtsp-restream # 使用转流一定要修改为preset-rtsp-restream
roles:
- record
- detect
- audio # <- 仅在启用音频检测时需要有子流情况下的配置
与摄像头建立两个连接。一个用于子流,一个用于转流,record连接到转流。
go2rtc:
streams:
name_your_rtsp_cam: # <- 你的RTSP流名称,修改为你自己希望的摄像头名称,只支持英文数字下划线和连接符
- rtsp://192.168.1.5:554/live0 # <- 支持视频和AAC音频的流。仅适用于RTSP流,HTTP必须使用ffmpeg
- 'ffmpeg:name_your_rtsp_cam#audio=opus' # <- 将音频转码为opus的流副本
name_your_rtsp_cam_sub: # <- 你的RTSP流名称,添加_sub代表这是子流,只要你能区分开,此处不强求名称。修改为你自己希望的摄像头名称,只支持英文数字下划线和连接符
- rtsp://192.168.1.5:554/substream # <- 支持视频和AAC音频的流。仅适用于RTSP流,HTTP必须使用ffmpeg
- 'ffmpeg:name_your_rtsp_cam_sub#audio=opus' # <- 将音频转码为opus的流副本
name_your_http_cam:
- http://192.168.50.155/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=user&password=password # <- 支持视频和AAC音频的流。仅适用于RTSP流,HTTP必须使用ffmpeg
- 'ffmpeg:name_your_http_cam#audio=opus' # <- 将音频转码为opus的流副本
name_your_http_cam_sub:
- http://192.168.50.155/flv?port=1935&app=bcs&stream=channel0_ext.bcs&user=user&password=password # <- 支持视频和AAC音频的流。仅适用于RTSP流,HTTP必须使用ffmpeg
- 'ffmpeg:name_your_http_cam_sub#audio=opus' # <- 将音频转码为opus的流副本
cameras:
name_your_rtsp_cam: # <- 摄像头名称和go2rtc上的视频流名称尽可能一致
ffmpeg:
output_args:
record: preset-record-generic-audio-copy
inputs:
- path: rtsp://127.0.0.1:8554/name_your_rtsp_cam # <--- 这里的名称必须与转流中的摄像头名称匹配
input_args: preset-rtsp-restream # 使用转流一定要修改为preset-rtsp-restream
roles: # 设置这个流的功能,包含record、audio和detect
- record # roles只有record代表这个流只用于录制
- path: rtsp://127.0.0.1:8554/name_your_rtsp_cam_sub # <--- 这里的名称必须与转流中的camera_sub名称匹配
input_args: preset-rtsp-restream # 使用转流一定要修改为preset-rtsp-restream
roles: # 设置这个流的功能
- audio # 设置该流将用于音频事件检测
- detect # 设置该流将用于物体/目标检测
name_your_http_cam: # 第二个摄像头,和上一个摄像头的设置方法一致
ffmpeg:
output_args:
record: preset-record-generic-audio-copy
inputs:
- path: rtsp://127.0.0.1:8554/name_your_http_cam # <--- 这里的名称必须与转流中的摄像头名称匹配
input_args: preset-rtsp-restream
roles:
- record
- path: rtsp://127.0.0.1:8554/name_your_http_cam_sub # <--- 这里的名称必须与转流中的camera_sub名称匹配
input_args: preset-rtsp-restream
roles:
- audio
- detect处理复杂密码(例如带特殊符号)
如果你的摄像头密码里有特殊符号,需要对密码进行 URL 编码才能正常识别。可以使用urlencoder.org进行编码。
警告
注意,只需要对用户名或者密码进行编码!不要把地址直接复制过去进行编码!
例如:
go2rtc:
streams:
my_camera: rtsp://username:$@foo%@192.168.1.100 # <- 假设你的密码是$@foo%,由于URL里@符号有其他用途,会导致这个地址无效 #编码后变为:
go2rtc:
streams:
my_camera: rtsp://username:$%40foo%25@192.168.1.100 # <- 经过url编码后,会将@符号转换为%40,%符号转为%25 #更多信息请参阅此评论。
Preventing go2rtc from blocking two-way audio
For cameras that support two-way talk, go2rtc will automatically establish an audio output backchannel when connecting to an RTSP stream. This backchannel blocks access to the camera's audio output for two-way talk functionality, preventing both Frigate and other applications from using it.
To prevent this, you must configure two separate stream instances:
- One stream instance with
#backchannel=0for Frigate's viewing, recording, and detection (prevents go2rtc from establishing the blocking backchannel) - A second stream instance without
#backchannel=0for two-way talk functionality (can be used by Frigate's WebRTC viewer or other applications)
Configuration example:
go2rtc:
streams:
front_door:
- rtsp://user:password@10.0.10.10:554/cam/realmonitor?channel=1&subtype=2#backchannel=0
front_door_twoway:
- rtsp://user:password@10.0.10.10:554/cam/realmonitor?channel=1&subtype=2In this configuration:
front_doorstream is used by Frigate for viewing, recording, and detection. The#backchannel=0parameter prevents go2rtc from establishing the audio output backchannel, so it won't block two-way talk access.front_door_twowaystream is used for two-way talk functionality. This stream can be used by Frigate's WebRTC viewer when two-way talk is enabled, or by other applications (like Home Assistant Advanced Camera Card) that need access to the camera's audio output channel.
高级转流配置
go2rtc 中的exec源可用于自定义 ffmpeg 命令。示例如下:
注意:output 需要使用两个花括号传递,如{{output}}
go2rtc:
streams:
stream1: exec:ffmpeg -hide_banner -re -stream_loop -1 -i /media/BigBuckBunny.mp4 -c copy -rtsp_transport tcp -f rtsp {{output}}