Skip to content

Commit 13f11e9

Browse files
authored
Merge pull request #40 from hawkeye217/multistream-speed
Multistream speed
2 parents 9efc20e + d13305c commit 13f11e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4941
-852
lines changed

docs/docs/configuration/live.md

+61-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ id: live
33
title: Live View
44
---
55

6-
Frigate intelligently displays your camera streams on the Live view dashboard. Your camera images update once per minute when no detectable activity is occurring to conserve bandwidth and resources. As soon as any motion is detected, cameras seamlessly switch to a live stream.
6+
Frigate intelligently displays your camera streams on the Live view dashboard. By default, Frigate employs "smart streaming" where camera images update once per minute when no detectable activity is occurring to conserve bandwidth and resources. As soon as any motion or objects are detected, cameras seamlessly switch to a live stream.
77

88
## Live View technologies
99

@@ -51,9 +51,15 @@ go2rtc:
5151
- ffmpeg:rtsp://192.168.1.5:554/live0#video=copy
5252
```
5353
54-
### Setting Stream For Live UI
54+
### Setting Streams For Live UI
5555
56-
There may be some cameras that you would prefer to use the sub stream for live view, but the main stream for recording. This can be done via `live -> stream_name`.
56+
In Frigate 0.16 and later, you can edit your configuration to allow manual selection of the stream you want to view in the Live UI. For example, you may want to view your camera's substream on mobile devices, but the full resolution stream on desktop devices. Setting the `live -> streams` list will populate a dropdown in the UI's Live view that allows you to choose between the streams. This settings is _per device_ and is saved in your device's local storage.
57+
58+
Additionally, when creating and editing camera groups in the UI, you can choose the stream you want to use for your camera group's Live dashboard. The default dashboard ("All Cameras") will always use the first entry you've defined in `streams:` for streaming.
59+
60+
Configure the `streams` option with a "friendly name" for your stream followed by the go2rtc stream name.
61+
62+
Go2rtc is required to use this feature. You cannot specify paths in the `streams` list, only go2rtc stream names.
5763

5864
```yaml
5965
go2rtc:
@@ -80,7 +86,9 @@ cameras:
8086
roles:
8187
- detect
8288
live:
83-
stream_name: test_cam_sub
89+
streams: # <--- Multiple streams for Frigate 0.16 and later
90+
- Main Stream: test_cam
91+
- Sub Stream: test_cam_sub
8492
```
8593

8694
### WebRTC extra configuration:
@@ -139,6 +147,54 @@ services:
139147

140148
See [go2rtc WebRTC docs](https://github.com/AlexxIT/go2rtc/tree/v1.8.3#module-webrtc) for more information about this.
141149

150+
151+
### Streaming options on camera group dashboards
152+
153+
Frigate 0.16 and later provides a dialog in the Camera Group Edit pane with several options for streaming on a camera group's dashboard. These settings are _per device_ and are saved in your device's local storage.
154+
155+
- Stream selection using the `live -> streams` configuration option (see _Setting Streams For Live UI_ above)
156+
- Streaming type:
157+
- _No streaming_: Camera images will only update once per minute and no live streaming will occur.
158+
- _Smart Streaming_ (default, recommended setting): Smart streaming will update your camera image once per minute when no detectable activity is occurring to conserve bandwidth and resources, since a static picture is the same as a streaming image with no motion or objects. When motion or objects are detected, the image seamlessly switches to a live stream.
159+
- _Continuous Streaming_: Camera image will always be a live stream when visible on the dashboard, even if no activity is being detected. Continuous streaming may cause high bandwidth usage and performance issues. **Use with caution.**
160+
- _Compatibility mode_: Enable this option only if your camera's live stream is displaying color artifacts and has a diagonal line on the right side of the image. Before enabling this, try setting your camera's `detect` width and height to a standard aspect ratio (for example: 640x352 becomes 640x360, and 800x443 becomes 800x450, 2688x1520 becomes 2688x1512, etc). Depending on your browser and device, more than a few cameras in compatibility mode may not be supported, so only use this option if changing your config fails to resolve the color artifacts and diagonal line.
161+
162+
:::note
163+
164+
The default dashboard ("All Cameras") will always use Smart Streaming and the first entry set in your `streams` configuration, if defined. Use a camera group if you want to change any of these settings from the defaults.
165+
166+
:::
167+
168+
## Live view FAQ
169+
170+
1. Why don't I have audio in my Live view?
171+
You must use go2rtc to hear audio in your live streams. If you have go2rtc already configured, you need to ensure your camera is sending AAC audio. If you can't change your camera's audio codec, you need to [transcode the audio to AAC](https://github.com/AlexxIT/go2rtc?tab=readme-ov-file#source-ffmpeg) using go2rtc.
172+
173+
Note that the low bandwidth mode player is a video-only stream. You should not expect to hear audio, even if you've set up go2rtc.
174+
175+
2. Frigate 0.16 shows that my live stream is in "low bandwidth mode". What does this mean?
176+
Frigate 0.14 and later intelligently selects the live streaming technology based on a number of factors (user-selected modes like two-way talk, camera settings, browser capabilities, available bandwidth) and prioritizes showing an actual up-to-date live view of your camera's stream as quickly as possible.
177+
178+
When you have go2rtc configured, Live view initially attempts to load and play back your stream with a clearer, fluent stream technology (MSE). An initial timeout, a low bandwidth condition that would cause buffering of the stream, or decoding errors in the stream will cause Frigate to switch to the stream defined by the `detect` role, using the jsmpeg format. This is what the UI calls "low bandwidth mode". You can try using the "reset" button to force a reload of your stream.
179+
180+
If you are still having issues with Frigate falling back to low bandwidth mode, you may need to adjust your camera's settings per the recommendations above.
181+
182+
3. It doesn't seem like my cameras are streaming on the Live dashboard. Why?
183+
On the default Live dashboard, your camera images will update once per minute when no detectable activity is occurring to conserve bandwidth and resources. As soon as any motion is detected, cameras seamlessly switch to a full-resolution live stream.
184+
185+
4. I see a strange diagonal line on my live view, but my recordings look fine. How can I fix it?
186+
This is caused by incorrect dimensions set in your detect width or height (or incorrectly auto-detected), causing the jsmpeg player's rendering engine to display a slightly distorted image. You should enlarge the width and height of your `detect` resolution up to a standard aspect ratio (example: 640x352 becomes 640x360, and 800x443 becomes 800x450, 2688x1520 becomes 2688x1512, etc). If changing the resolution to match a standard 4:3, 16:9, or 32:9 aspect ratio does not solve the issue, you can enable "compatibility mode" in your camera group dashboard's stream settings. Depending on your browser and device, more than a few cameras in compatibility mode may not be supported, so only use this option if changing your `detect` width and height fails to resolve the color artifacts and diagonal line.
187+
188+
5. How does "smart streaming" work?
189+
This feature was introduced in Frigate 0.14 with the Live dashboard. Because a static image of a scene looks exactly the same as a live stream with no motion or activity, smart streaming updates your camera images once per minute when no detectable activity is occurring to conserve bandwidth and resources. As soon as any motion is detected, cameras seamlessly switch to a live stream.
190+
191+
This static image is pulled from the stream defined in your config with the `detect` role. When activity is detected, images from the `detect` stream immediately begin updating at ~5 frames per second until the live player is loaded and begins playing. This usually only takes a second or two. If the live player times out, buffers, or has streaming errors, the jsmpeg player is loaded and plays a video-only stream from the `detect` role. When activity ends, the players are destroyed and a static image is displayed until activity is detected again, and the process repeats.
192+
193+
This is Frigate's default and recommended setting because it results in a significant bandwidth savings, especially for high resolution cameras.
194+
195+
6. I have unmuted some cameras on my dashboard, but I do not hear sound. Why?
196+
If your camera is streaming (as indicated by a red dot in the upper right, or if it has been set to continuous streaming mode), your browser may be blocking audio until you interact with the page. This is an intentional browser limitation. See [this article](https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide#autoplay_availability). Many browsers have a whitelist feature to change this behavior.
197+
142198
### Two way talk
143199

144200
For devices that support two way talk, Frigate can be configured to use the feature from the camera's Live view in the Web UI. You should:
@@ -148,3 +204,4 @@ For devices that support two way talk, Frigate can be configured to use the feat
148204
- For the Home Assistant Frigate card, [follow the docs](https://github.com/dermotduffy/frigate-hass-card?tab=readme-ov-file#using-2-way-audio) for the correct source.
149205

150206
To use the Reolink Doorbell with two way talk, you should use the [recommended Reolink configuration](/configuration/camera_specific#reolink-doorbell)
207+

docs/docs/configuration/reference.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,11 @@ go2rtc:
555555
# Optional: Live stream configuration for WebUI.
556556
# NOTE: Can be overridden at the camera level
557557
live:
558-
# Optional: Set the name of the stream configured in go2rtc
558+
# Optional: Set the streams configured in go2rtc
559559
# that should be used for live view in frigate WebUI. (default: name of camera)
560560
# NOTE: In most cases this should be set at the camera level only.
561-
stream_name: camera_name
561+
streams:
562+
- friendly_name: stream_name
562563
# Optional: Set the height of the jsmpeg stream. (default: 720)
563564
# This must be less than or equal to the height of the detect stream. Lower resolutions
564565
# reduce bandwidth required for viewing the jsmpeg stream. Width is computed to match known aspect ratio.
@@ -643,7 +644,10 @@ cameras:
643644
front_steps:
644645
# Required: List of x,y coordinates to define the polygon of the zone.
645646
# NOTE: Presence in a zone is evaluated only based on the bottom center of the objects bounding box.
646-
coordinates: 0.284,0.997,0.389,0.869,0.410,0.745
647+
coordinates: 0.033,0.306,0.324,0.138,0.439,0.185,0.042,0.428
648+
# Optional: The real-world distances of a 4-sided zone used for zones with speed estimation enabled (default: none)
649+
# List distances in order of the zone points coordinates and use the unit system defined in the ui config
650+
distances: 10,15,12,11
647651
# Optional: Number of consecutive frames required for object to be considered present in the zone (default: shown below).
648652
inertia: 3
649653
# Optional: Number of seconds that an object must loiter to be considered in the zone (default: shown below)
@@ -794,6 +798,9 @@ ui:
794798
# https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html
795799
# possible values are shown above (default: not set)
796800
strftime_fmt: "%Y/%m/%d %H:%M"
801+
# Optional: Set the unit system to either "imperial" or "metric" (default: metric)
802+
# Used in the UI and in MQTT topics
803+
unit_system: metric
797804

798805
# Optional: Telemetry configuration
799806
telemetry:

docs/docs/configuration/zones.md

+34-6
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,44 @@ cameras:
122122
- car
123123
```
124124

125-
### Loitering Time
125+
### Speed Estimation
126126

127-
Zones support a `loitering_time` configuration which can be used to only consider an object as part of a zone if they loiter in the zone for the specified number of seconds. This can be used, for example, to create alerts for cars that stop on the street but not cars that just drive past your camera.
127+
Frigate can be configured to estimate the speed of objects moving through a zone. This works by combining data from Frigate's object tracker and "real world" distance measurements of the edges of the zone. The recommended use case for this feature is to track the speed of vehicles on a road as they move through the zone.
128+
129+
Your zone must be defined with exactly 4 points and should be aligned to the ground where objects are moving.
130+
131+
![Ground plane 4-point zone](/img/ground-plane.jpg)
132+
133+
Speed estimation requires a minimum number of frames for your object to be tracked before a valid estimate can be calculated, so create your zone away from places where objects enter and exit for the best results. _Your zone should not take up the full frame._ An object's speed is tracked while it is in the zone and then saved to Frigate's database.
134+
135+
Accurate real-world distance measurements are required to estimate speeds. These distances can be specified in your zone config through the `distances` field.
128136

129137
```yaml
130138
cameras:
131139
name_of_your_camera:
132140
zones:
133-
front_yard:
134-
loitering_time: 5 # unit is in seconds
135-
objects:
136-
- person
141+
street:
142+
coordinates: 0.033,0.306,0.324,0.138,0.439,0.185,0.042,0.428
143+
distances: 10,12,11,13.5
137144
```
145+
146+
Each number in the `distance` field represents the real-world distance between the points in the `coordinates` list. So in the example above, the distance between the first two points ([0.033,0.306] and [0.324,0.138]) is 10. The distance between the second and third set of points ([0.324,0.138] and [0.439,0.185]) is 12, and so on. The fastest and most accurate way to configure this is through the Zone Editor in the Frigate UI.
147+
148+
The `distance` values are measured in meters or feet, depending on how `unit_system` is configured in your `ui` config:
149+
150+
```yaml
151+
ui:
152+
# can be "metric" or "imperial", default is metric
153+
unit_system: metric
154+
```
155+
156+
The average speed of your object as it moved through your zone is saved in Frigate's database and can be seen in the UI in the Tracked Object Details pane in Explore. Current estimated speed can also be seen on the debug view as the third value in the object label (see the caveats below). Current estimated speed, average estimated speed, and velocity angle (the angle of the direction the object is moving relative to the frame) of tracked objects is also sent through the `events` MQTT topic. See the [MQTT docs](../integrations/mqtt.md#frigateevents). These speed values are output as a number in miles per hour (mph) or kilometers per hour (kph), depending on how `unit_system` is configured in your `ui` config.
157+
158+
#### Best practices and caveats
159+
160+
- Speed estimation works best with a straight road or path when your object travels in a straight line across that path. If your object makes turns, speed estimation may not be accurate.
161+
- Create a zone where the bottom center of your object's bounding box travels directly through it and does not become obscured at any time.
162+
- Depending on the size and location of your zone, you may want to decrease the zone's `inertia` value from the default of 3.
163+
- The more accurate your real-world dimensions can be measured, the more accurate speed estimation will be. However, due to the way Frigate's tracking algorithm works, you may need to tweak the real-world distance values so that estimated speeds better match real-world speeds.
164+
- Once an object leaves the zone, speed accuracy will likely decrease due to perspective distortion and misalignment with the calibrated area.
165+
- The speeds are only an _estimation_ and are highly dependent on camera position, zone points, and real-world measurements. This feature should not be used for law enforcement.

docs/docs/integrations/mqtt.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ Message published for each changed tracked object. The first message is publishe
5252
"attributes": {
5353
"face": 0.64
5454
}, // attributes with top score that have been identified on the object at any point
55-
"current_attributes": [] // detailed data about the current attributes in this frame
55+
"current_attributes": [], // detailed data about the current attributes in this frame
56+
"current_estimated_speed": 0.71, // current estimated speed (mph or kph) for objects moving through zones with speed estimation enabled
57+
"velocity_angle": 180 // direction of travel relative to the frame for objects moving through zones with speed estimation enabled
5658
},
5759
"after": {
5860
"id": "1607123955.475377-mxklsc",
@@ -89,7 +91,9 @@ Message published for each changed tracked object. The first message is publishe
8991
"box": [442, 506, 534, 524],
9092
"score": 0.86
9193
}
92-
]
94+
],
95+
"current_estimated_speed": 0.77, // current estimated speed (mph or kph) for objects moving through zones with speed estimation enabled
96+
"velocity_angle": 180 // direction of travel relative to the frame for objects moving through zones with speed estimation enabled
9397
}
9498
}
9599
```

docs/static/img/ground-plane.jpg

92 KB
Loading

frigate/api/defs/query/events_query_parameters.py

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class EventsQueryParams(BaseModel):
2525
favorites: Optional[int] = None
2626
min_score: Optional[float] = None
2727
max_score: Optional[float] = None
28+
min_speed: Optional[float] = None
29+
max_speed: Optional[float] = None
2830
is_submitted: Optional[int] = None
2931
min_length: Optional[float] = None
3032
max_length: Optional[float] = None
@@ -51,6 +53,8 @@ class EventsSearchQueryParams(BaseModel):
5153
timezone: Optional[str] = "utc"
5254
min_score: Optional[float] = None
5355
max_score: Optional[float] = None
56+
min_speed: Optional[float] = None
57+
max_speed: Optional[float] = None
5458
sort: Optional[str] = None
5559

5660

0 commit comments

Comments
 (0)