config.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import voluptuous as vol
  2. DETECTORS_SCHEMA = vol.Schema(
  3. {
  4. vol.Required(str): {
  5. vol.Required('type', default='edgetpu'): vol.In(['cpu', 'edgetpu']),
  6. vol.Optional('device', default='usb'): str
  7. }
  8. }
  9. )
  10. DEFAULT_DETECTORS = {
  11. 'coral': {
  12. 'type': 'edgetpu',
  13. 'device': 'usb'
  14. }
  15. }
  16. MQTT_SCHEMA = vol.Schema(
  17. {
  18. vol.Required('host'): str,
  19. vol.Optional('port', default=1883): int,
  20. vol.Optional('topic_prefix', default='frigate'): str,
  21. vol.Optional('client_id', default='frigate'): str,
  22. 'user': str,
  23. 'password': str
  24. }
  25. )
  26. SAVE_CLIPS_SCHEMA = vol.Schema(
  27. {
  28. vol.Optional('max_seconds', default=300): int,
  29. vol.Optional('clips_dir', default='/clips'): str,
  30. vol.Optional('cache_dir', default='/cache'): str
  31. }
  32. )
  33. FFMPEG_GLOBAL_ARGS_DEFAULT = ['-hide_banner','-loglevel','panic']
  34. FFMPEG_INPUT_ARGS_DEFAULT = ['-avoid_negative_ts', 'make_zero',
  35. '-fflags', 'nobuffer',
  36. '-flags', 'low_delay',
  37. '-strict', 'experimental',
  38. '-fflags', '+genpts+discardcorrupt',
  39. '-rtsp_transport', 'tcp',
  40. '-stimeout', '5000000',
  41. '-use_wallclock_as_timestamps', '1']
  42. FFMPEG_OUTPUT_ARGS_DEFAULT = ['-f', 'rawvideo',
  43. '-pix_fmt', 'yuv420p']
  44. GLOBAL_FFMPEG_SCHEMA = vol.Schema(
  45. {
  46. vol.Optional('global_args', default=FFMPEG_GLOBAL_ARGS_DEFAULT): [str],
  47. vol.Optional('hwaccel_args', default=[]): [str],
  48. vol.Optional('input_args', default=FFMPEG_INPUT_ARGS_DEFAULT): [str],
  49. vol.Optional('output_args', default=FFMPEG_OUTPUT_ARGS_DEFAULT): [str]
  50. }
  51. )
  52. FILTER_SCHEMA = vol.Schema(
  53. {
  54. str: {
  55. vol.Optional('min_area', default=0): int,
  56. vol.Optional('max_area', default=24000000): int,
  57. vol.Optional('threshold', default=0.85): float
  58. }
  59. }
  60. )
  61. OBJECTS_SCHEMA = vol.Schema(
  62. {
  63. vol.Optional('track', default=['person']): [str],
  64. 'filters': FILTER_SCHEMA.extend({vol.Optional('min_score', default=0.5): float})
  65. }
  66. )
  67. DEFAULT_CAMERA_MQTT = {
  68. 'crop_to_region': True
  69. }
  70. DEFAULT_CAMERA_SAVE_CLIPS = {
  71. 'enabled': False
  72. }
  73. DEFAULT_CAMERA_SNAPSHOTS = {
  74. 'show_timestamp': True,
  75. 'draw_zones': False,
  76. 'draw_bounding_boxes': True
  77. }
  78. CAMERA_FFMPEG_SCHEMA = vol.Schema(
  79. {
  80. vol.Required('input'): str,
  81. 'global_args': [str],
  82. 'hwaccel_args': [str],
  83. 'input_args': [str],
  84. 'output_args': [str]
  85. }
  86. )
  87. CAMERAS_SCHEMA = vol.Schema(
  88. {
  89. str: {
  90. vol.Required('ffmpeg'): CAMERA_FFMPEG_SCHEMA,
  91. 'height': int,
  92. 'width': int,
  93. 'fps': int,
  94. 'mask': str,
  95. vol.Optional('best_image_timeout', default=60): int,
  96. vol.Optional('mqtt', default=DEFAULT_CAMERA_MQTT): {
  97. vol.Optional('crop_to_region', default=True): bool,
  98. 'snapshot_height': int
  99. },
  100. vol.Optional('zones', default={}): {
  101. str: {
  102. vol.Required('coordinates'): vol.Any(str, [str]),
  103. 'filters': FILTER_SCHEMA
  104. }
  105. },
  106. vol.Optional('save_clips', default=DEFAULT_CAMERA_SAVE_CLIPS): {
  107. vol.Optional('enabled', default=False): bool,
  108. vol.Optional('pre_capture', default=30): int,
  109. 'objects': [str],
  110. },
  111. vol.Optional('snapshots', default=DEFAULT_CAMERA_SNAPSHOTS): {
  112. vol.Optional('show_timestamp', default=True): bool,
  113. vol.Optional('draw_zones', default=False): bool,
  114. vol.Optional('draw_bounding_boxes', default=True): bool
  115. },
  116. 'objects': OBJECTS_SCHEMA
  117. }
  118. }
  119. )
  120. FRIGATE_CONFIG_SCHEMA = vol.Schema(
  121. {
  122. vol.Optional('web_port', default=5000): int,
  123. vol.Optional('detectors', default=DEFAULT_DETECTORS): DETECTORS_SCHEMA,
  124. 'mqtt': MQTT_SCHEMA,
  125. vol.Optional('save_clips', default={}): SAVE_CLIPS_SCHEMA,
  126. vol.Optional('ffmpeg', default={}): GLOBAL_FFMPEG_SCHEMA,
  127. vol.Optional('objects', default={}): OBJECTS_SCHEMA,
  128. vol.Required('cameras', default={}): CAMERAS_SCHEMA
  129. }
  130. )