mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 10:45:21 +03:00
Build out base config
This commit is contained in:
parent
87a4d1d15b
commit
b6bb1cd185
@ -21,7 +21,6 @@ from frigate.comms.mqtt import MqttClient
|
|||||||
from frigate.comms.ws import WebSocketClient
|
from frigate.comms.ws import WebSocketClient
|
||||||
from frigate.config import FrigateConfig
|
from frigate.config import FrigateConfig
|
||||||
from frigate.const import (
|
from frigate.const import (
|
||||||
AUDIO_DETECTOR,
|
|
||||||
CACHE_DIR,
|
CACHE_DIR,
|
||||||
CLIPS_DIR,
|
CLIPS_DIR,
|
||||||
CONFIG_DIR,
|
CONFIG_DIR,
|
||||||
@ -30,8 +29,6 @@ from frigate.const import (
|
|||||||
MODEL_CACHE_DIR,
|
MODEL_CACHE_DIR,
|
||||||
RECORD_DIR,
|
RECORD_DIR,
|
||||||
)
|
)
|
||||||
from frigate.detectors.plugins.audio_tfl import AudioDetectorConfig
|
|
||||||
from frigate.events.audio import AudioDetectProcess
|
|
||||||
from frigate.events.cleanup import EventCleanup
|
from frigate.events.cleanup import EventCleanup
|
||||||
from frigate.events.external import ExternalEventProcessor
|
from frigate.events.external import ExternalEventProcessor
|
||||||
from frigate.events.maintainer import EventProcessor
|
from frigate.events.maintainer import EventProcessor
|
||||||
@ -62,7 +59,6 @@ class FrigateApp:
|
|||||||
self.detectors: dict[str, ObjectDetectProcess] = {}
|
self.detectors: dict[str, ObjectDetectProcess] = {}
|
||||||
self.detection_out_events: dict[str, MpEvent] = {}
|
self.detection_out_events: dict[str, MpEvent] = {}
|
||||||
self.detection_shms: list[mp.shared_memory.SharedMemory] = []
|
self.detection_shms: list[mp.shared_memory.SharedMemory] = []
|
||||||
self.audio_queue: Queue = mp.Queue()
|
|
||||||
self.log_queue: Queue = mp.Queue()
|
self.log_queue: Queue = mp.Queue()
|
||||||
self.plus_api = PlusApi()
|
self.plus_api = PlusApi()
|
||||||
self.camera_metrics: dict[str, CameraMetricsTypes] = {}
|
self.camera_metrics: dict[str, CameraMetricsTypes] = {}
|
||||||
@ -290,8 +286,6 @@ class FrigateApp:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def start_detectors(self) -> None:
|
def start_detectors(self) -> None:
|
||||||
audio_enabled = any(c.audio.enabled for c in self.config.cameras.items())
|
|
||||||
|
|
||||||
for name in self.config.cameras.keys():
|
for name in self.config.cameras.keys():
|
||||||
self.detection_out_events[name] = mp.Event()
|
self.detection_out_events[name] = mp.Event()
|
||||||
|
|
||||||
@ -320,33 +314,6 @@ class FrigateApp:
|
|||||||
self.detection_shms.append(shm_in)
|
self.detection_shms.append(shm_in)
|
||||||
self.detection_shms.append(shm_out)
|
self.detection_shms.append(shm_out)
|
||||||
|
|
||||||
|
|
||||||
if audio_enabled:
|
|
||||||
try:
|
|
||||||
shm_in_audio = mp.shared_memory.SharedMemory(
|
|
||||||
name=f"{name}-audio",
|
|
||||||
create=True,
|
|
||||||
size=int(
|
|
||||||
round(
|
|
||||||
self.config.audio_model.duration
|
|
||||||
* self.config.audio_model.sample_rate
|
|
||||||
)
|
|
||||||
)
|
|
||||||
* 4, # stored as float32, so 4 bytes per sample
|
|
||||||
)
|
|
||||||
except FileExistsError:
|
|
||||||
shm_in_audio = mp.shared_memory.SharedMemory(name=f"{name}-audio")
|
|
||||||
|
|
||||||
try:
|
|
||||||
shm_out_audio = mp.shared_memory.SharedMemory(
|
|
||||||
name=f"out-{name}-audio", create=True, size=20 * 6 * 4
|
|
||||||
)
|
|
||||||
except FileExistsError:
|
|
||||||
shm_out_audio = mp.shared_memory.SharedMemory(
|
|
||||||
name=f"out-{name}-audio"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
for name, detector_config in self.config.detectors.items():
|
for name, detector_config in self.config.detectors.items():
|
||||||
self.detectors[name] = ObjectDetectProcess(
|
self.detectors[name] = ObjectDetectProcess(
|
||||||
name,
|
name,
|
||||||
@ -355,14 +322,6 @@ class FrigateApp:
|
|||||||
detector_config,
|
detector_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
if audio_enabled:
|
|
||||||
self.detectors[AUDIO_DETECTOR] = AudioDetectProcess(
|
|
||||||
AUDIO_DETECTOR,
|
|
||||||
self.audio_queue,
|
|
||||||
self.detection_out_events,
|
|
||||||
AudioDetectorConfig
|
|
||||||
)
|
|
||||||
|
|
||||||
def start_detected_frames_processor(self) -> None:
|
def start_detected_frames_processor(self) -> None:
|
||||||
self.detected_frames_processor = TrackedObjectProcessor(
|
self.detected_frames_processor = TrackedObjectProcessor(
|
||||||
self.config,
|
self.config,
|
||||||
|
|||||||
@ -15,6 +15,9 @@ BTBN_PATH = "/usr/lib/btbn-ffmpeg"
|
|||||||
# Audio Consts
|
# Audio Consts
|
||||||
|
|
||||||
AUDIO_DETECTOR = "audio-detector"
|
AUDIO_DETECTOR = "audio-detector"
|
||||||
|
AUDIO_DURATION = 0.975
|
||||||
|
AUDIO_FORMAT = "s16le"
|
||||||
|
AUDIO_SAMPLE_RATE = 16000
|
||||||
|
|
||||||
# Regex Consts
|
# Regex Consts
|
||||||
|
|
||||||
|
|||||||
@ -10,12 +10,20 @@ from typing import Optional
|
|||||||
from setproctitle import setproctitle
|
from setproctitle import setproctitle
|
||||||
|
|
||||||
from frigate.config import AudioConfig, CameraConfig, FrigateConfig
|
from frigate.config import AudioConfig, CameraConfig, FrigateConfig
|
||||||
from frigate.const import CACHE_DIR
|
from frigate.const import (
|
||||||
|
AUDIO_DETECTOR,
|
||||||
|
AUDIO_DURATION,
|
||||||
|
AUDIO_FORMAT,
|
||||||
|
AUDIO_SAMPLE_RATE,
|
||||||
|
CACHE_DIR,
|
||||||
|
)
|
||||||
from frigate.util import listen
|
from frigate.util import listen
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
FFMPEG_COMMAND = "ffmpeg -vn -i {} -f s16le -ar 16000 -ac 1 -y {}"
|
FFMPEG_COMMAND = (
|
||||||
|
f"ffmpeg -vn -i {{}} -f {AUDIO_FORMAT} -ar {AUDIO_SAMPLE_RATE} -ac 1 -y {{}}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def listen_to_audio(config: FrigateConfig, event_queue: mp.Queue) -> None:
|
def listen_to_audio(config: FrigateConfig, event_queue: mp.Queue) -> None:
|
||||||
@ -36,55 +44,19 @@ def listen_to_audio(config: FrigateConfig, event_queue: mp.Queue) -> None:
|
|||||||
AudioEventMaintainer(camera, stop_event)
|
AudioEventMaintainer(camera, stop_event)
|
||||||
|
|
||||||
|
|
||||||
class AudioDetectProcess:
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
name,
|
|
||||||
detection_queue,
|
|
||||||
out_events,
|
|
||||||
):
|
|
||||||
self.name = name
|
|
||||||
self.out_events = out_events
|
|
||||||
self.detection_queue = detection_queue
|
|
||||||
self.detect_process = None
|
|
||||||
self.start_or_restart()
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
# if the process has already exited on its own, just return
|
|
||||||
if self.detect_process and self.detect_process.exitcode:
|
|
||||||
return
|
|
||||||
self.detect_process.terminate()
|
|
||||||
logging.info("Waiting for detection process to exit gracefully...")
|
|
||||||
self.detect_process.join(timeout=30)
|
|
||||||
if self.detect_process.exitcode is None:
|
|
||||||
logging.info("Detection process didnt exit. Force killing...")
|
|
||||||
self.detect_process.kill()
|
|
||||||
self.detect_process.join()
|
|
||||||
logging.info("Detection process has exited...")
|
|
||||||
|
|
||||||
def start_or_restart(self):
|
|
||||||
self.detection_start.value = 0.0
|
|
||||||
if (self.detect_process is not None) and self.detect_process.is_alive():
|
|
||||||
self.stop()
|
|
||||||
self.detect_process = mp.Process(
|
|
||||||
target=run_detector,
|
|
||||||
name=f"detector:{self.name}",
|
|
||||||
args=(
|
|
||||||
self.name,
|
|
||||||
self.detection_queue,
|
|
||||||
self.out_events,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
self.detect_process.daemon = True
|
|
||||||
self.detect_process.start()
|
|
||||||
|
|
||||||
|
|
||||||
class AudioEventMaintainer(threading.Thread):
|
class AudioEventMaintainer(threading.Thread):
|
||||||
def __init__(self, camera: CameraConfig, stop_event: mp.Event) -> None:
|
def __init__(self, camera: CameraConfig, stop_event: mp.Event) -> None:
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.name = f"{camera.name}_audio_event_processor"
|
self.name = f"{camera.name}_audio_event_processor"
|
||||||
self.config = camera
|
self.config = camera
|
||||||
self.stop_event = stop_event
|
self.stop_event = stop_event
|
||||||
|
self.shape = (int(round(AUDIO_DURATION * AUDIO_SAMPLE_RATE)),)
|
||||||
|
|
||||||
|
def detect_audio(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def listen_to_audio(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self.pipe = f"{CACHE_DIR}/{self.config.name}-audio"
|
self.pipe = f"{CACHE_DIR}/{self.config.name}-audio"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user