123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- import json
- from unittest import TestCase, main
- import voluptuous as vol
- from frigate.config import FRIGATE_CONFIG_SCHEMA, FrigateConfig
- class TestConfig(TestCase):
- def setUp(self):
- self.minimal = {
- "mqtt": {"host": "mqtt"},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- }
- },
- }
- def test_empty(self):
- FRIGATE_CONFIG_SCHEMA({})
- def test_minimal(self):
- FRIGATE_CONFIG_SCHEMA(self.minimal)
- def test_config_class(self):
- FrigateConfig(config=self.minimal)
- def test_inherit_tracked_objects(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "objects": {"track": ["person", "dog"]},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- }
- },
- }
- frigate_config = FrigateConfig(config=config)
- assert "dog" in frigate_config.cameras["back"].objects.track
- def test_override_tracked_objects(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "objects": {"track": ["person", "dog"]},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- "objects": {"track": ["cat"]},
- }
- },
- }
- frigate_config = FrigateConfig(config=config)
- assert "cat" in frigate_config.cameras["back"].objects.track
- def test_default_object_filters(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "objects": {"track": ["person", "dog"]},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- }
- },
- }
- frigate_config = FrigateConfig(config=config)
- assert "dog" in frigate_config.cameras["back"].objects.filters
- def test_inherit_object_filters(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "objects": {
- "track": ["person", "dog"],
- "filters": {"dog": {"threshold": 0.7}},
- },
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- }
- },
- }
- frigate_config = FrigateConfig(config=config)
- assert "dog" in frigate_config.cameras["back"].objects.filters
- assert frigate_config.cameras["back"].objects.filters["dog"].threshold == 0.7
- def test_override_object_filters(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- "objects": {
- "track": ["person", "dog"],
- "filters": {"dog": {"threshold": 0.7}},
- },
- }
- },
- }
- frigate_config = FrigateConfig(config=config)
- assert "dog" in frigate_config.cameras["back"].objects.filters
- assert frigate_config.cameras["back"].objects.filters["dog"].threshold == 0.7
- def test_global_object_mask(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "objects": {"track": ["person", "dog"]},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- "objects": {
- "mask": "0,0,1,1,0,1",
- "filters": {"dog": {"mask": "1,1,1,1,1,1"}},
- },
- }
- },
- }
- frigate_config = FrigateConfig(config=config)
- assert "dog" in frigate_config.cameras["back"].objects.filters
- assert len(frigate_config.cameras["back"].objects.filters["dog"]._raw_mask) == 2
- assert (
- len(frigate_config.cameras["back"].objects.filters["person"]._raw_mask) == 1
- )
- def test_ffmpeg_params_global(self):
- config = {
- "ffmpeg": {"input_args": ["-re"]},
- "mqtt": {"host": "mqtt"},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- "objects": {
- "track": ["person", "dog"],
- "filters": {"dog": {"threshold": 0.7}},
- },
- }
- },
- }
- frigate_config = FrigateConfig(config=config)
- assert "-re" in frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]
- def test_ffmpeg_params_camera(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ],
- "input_args": ["-re"],
- },
- "height": 1080,
- "width": 1920,
- "objects": {
- "track": ["person", "dog"],
- "filters": {"dog": {"threshold": 0.7}},
- },
- }
- },
- }
- frigate_config = FrigateConfig(config=config)
- assert "-re" in frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]
- def test_ffmpeg_params_input(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {
- "path": "rtsp://10.0.0.1:554/video",
- "roles": ["detect"],
- "input_args": ["-re"],
- }
- ]
- },
- "height": 1080,
- "width": 1920,
- "objects": {
- "track": ["person", "dog"],
- "filters": {"dog": {"threshold": 0.7}},
- },
- }
- },
- }
- frigate_config = FrigateConfig(config=config)
- assert "-re" in frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]
- def test_inherit_clips_retention(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "clips": {"retain": {"default": 20, "objects": {"person": 30}}},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- }
- },
- }
- frigate_config = FrigateConfig(config=config)
- assert frigate_config.cameras["back"].clips.retain.objects["person"] == 30
- def test_roles_listed_twice_throws_error(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "clips": {"retain": {"default": 20, "objects": {"person": 30}}},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]},
- {"path": "rtsp://10.0.0.1:554/video2", "roles": ["detect"]},
- ]
- },
- "height": 1080,
- "width": 1920,
- }
- },
- }
- self.assertRaises(vol.MultipleInvalid, lambda: FrigateConfig(config=config))
- def test_zone_matching_camera_name_throws_error(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "clips": {"retain": {"default": 20, "objects": {"person": 30}}},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- "zones": {"back": {"coordinates": "1,1,1,1,1,1"}},
- }
- },
- }
- self.assertRaises(vol.MultipleInvalid, lambda: FrigateConfig(config=config))
- def test_clips_should_default_to_global_objects(self):
- config = {
- "mqtt": {"host": "mqtt"},
- "clips": {"retain": {"default": 20, "objects": {"person": 30}}},
- "objects": {"track": ["person", "dog"]},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
- ]
- },
- "height": 1080,
- "width": 1920,
- "clips": {"enabled": True},
- }
- },
- }
- config = FrigateConfig(config=config)
- assert config.cameras["back"].clips.objects is None
- def test_role_assigned_but_not_enabled(self):
- json_config = {
- "mqtt": {"host": "mqtt"},
- "cameras": {
- "back": {
- "ffmpeg": {
- "inputs": [
- {
- "path": "rtsp://10.0.0.1:554/video",
- "roles": ["detect", "rtmp"],
- },
- {"path": "rtsp://10.0.0.1:554/record", "roles": ["record"]},
- ]
- },
- "height": 1080,
- "width": 1920,
- }
- },
- }
- config = FrigateConfig(config=json_config)
- ffmpeg_cmds = config.cameras["back"].ffmpeg_cmds
- assert len(ffmpeg_cmds) == 1
- assert not "clips" in ffmpeg_cmds[0]["roles"]
- if __name__ == "__main__":
- main(verbosity=2)
|