handle and warn if roles dont match enabled features

This commit is contained in:
Blake Blackshear 2020-12-07 08:07:35 -06:00
parent 953c442f13
commit 3c07767138
3 changed files with 54 additions and 1 deletions

View File

@ -67,6 +67,24 @@ class FrigateApp():
'ffmpeg_pid': mp.Value('i', 0),
'frame_queue': mp.Queue(maxsize=2)
}
def check_config(self):
for name, camera in self.config.cameras.items():
assigned_roles = list(set([r for i in camera.ffmpeg.inputs for r in i.roles]))
if not camera.save_clips.enabled and 'clips' in assigned_roles:
logger.warning(f"Camera {name} has clips assigned to an input, but save_clips is not enabled.")
elif camera.save_clips.enabled and not 'clips' in assigned_roles:
logger.warning(f"Camera {name} has save_clips enabled, but clips is not assigned to an input.")
if not camera.record.enabled and 'record' in assigned_roles:
logger.warning(f"Camera {name} has record assigned to an input, but record is not enabled.")
elif camera.record.enabled and not 'record' in assigned_roles:
logger.warning(f"Camera {name} has record enabled, but record is not assigned to an input.")
if not camera.rtmp.enabled and 'rtmp' in assigned_roles:
logger.warning(f"Camera {name} has rtmp assigned to an input, but rtmp is not enabled.")
elif camera.rtmp.enabled and not 'rtmp' in assigned_roles:
logger.warning(f"Camera {name} has rtmp enabled, but rtmp is not assigned to an input.")
def set_log_levels(self):
logging.getLogger().setLevel(self.config.logger.default)
@ -160,6 +178,7 @@ class FrigateApp():
logger.error(f"Error parsing config: {e}")
self.log_process.terminate()
sys.exit(1)
self.check_config()
self.set_log_levels()
self.init_queues()
self.init_database()

View File

@ -587,9 +587,13 @@ class CameraConfig():
self._ffmpeg_cmds = []
for ffmpeg_input in self._ffmpeg.inputs:
ffmpeg_cmd = self._get_ffmpeg_cmd(ffmpeg_input)
if ffmpeg_cmd is None:
continue
self._ffmpeg_cmds.append({
'roles': ffmpeg_input.roles,
'cmd': self._get_ffmpeg_cmd(ffmpeg_input)
'cmd': ffmpeg_cmd
})
@ -636,6 +640,11 @@ class CameraConfig():
ffmpeg_output_args = self.ffmpeg.output_args['record'] + [
f"{os.path.join(RECORD_DIR, self.name)}-%Y%m%d%H%M%S.mp4"
] + ffmpeg_output_args
# if there arent any outputs enabled for this input
if len(ffmpeg_output_args) == 0:
return None
return (['ffmpeg'] +
ffmpeg_input.global_args +
ffmpeg_input.hwaccel_args +

View File

@ -314,6 +314,31 @@ class TestConfig(TestCase):
assert(len(config.cameras['back'].save_clips.objects) == 2)
assert('dog' in config.cameras['back'].save_clips.objects)
assert('person' in config.cameras['back'].save_clips.objects)
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/clips', 'roles': ['clips'] }
]
},
'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)