mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 18:55:23 +03:00
End events if not heard for 30 seconds
This commit is contained in:
parent
734eb07a23
commit
1f1917742f
@ -114,7 +114,9 @@ class AudioTfl:
|
|||||||
|
|
||||||
|
|
||||||
class AudioEventMaintainer(threading.Thread):
|
class AudioEventMaintainer(threading.Thread):
|
||||||
def __init__(self, camera: CameraConfig, event_queue: mp.Queue, stop_event: mp.Event) -> None:
|
def __init__(
|
||||||
|
self, camera: CameraConfig, event_queue: mp.Queue, 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
|
||||||
@ -148,22 +150,41 @@ class AudioEventMaintainer(threading.Thread):
|
|||||||
|
|
||||||
self.handle_detection(label, score)
|
self.handle_detection(label, score)
|
||||||
|
|
||||||
|
self.expire_detections()
|
||||||
|
|
||||||
def handle_detection(self, label: str, score: float) -> None:
|
def handle_detection(self, label: str, score: float) -> None:
|
||||||
if self.detections[label] is not None:
|
if self.detections.get(label) is not None:
|
||||||
self.detections[label]["last_detection"] = datetime.datetime.now().timestamp()
|
self.detections[label][
|
||||||
|
"last_detection"
|
||||||
|
] = datetime.datetime.now().timestamp()
|
||||||
else:
|
else:
|
||||||
now = datetime.datetime.now().timestamp()
|
now = datetime.datetime.now().timestamp()
|
||||||
rand_id = "".join(random.choices(string.ascii_lowercase + string.digits, k=6))
|
rand_id = "".join(
|
||||||
|
random.choices(string.ascii_lowercase + string.digits, k=6)
|
||||||
|
)
|
||||||
event_id = f"{now}-{rand_id}"
|
event_id = f"{now}-{rand_id}"
|
||||||
self.detections[label] = {
|
self.detections[label] = {
|
||||||
"id": event_id,
|
"id": event_id,
|
||||||
"label": label,
|
"label": label,
|
||||||
"camera": self.config.name,
|
"camera": self.config.name,
|
||||||
"start_time": now,
|
"start_time": now - self.config.record.events.pre_capture,
|
||||||
"last_detection": now,
|
"last_detection": now,
|
||||||
}
|
}
|
||||||
self.queue.put((EventTypeEnum.audio, "start", self.config.name, self.detections[label]))
|
self.queue.put(
|
||||||
|
(EventTypeEnum.audio, "start", self.config.name, self.detections[label])
|
||||||
|
)
|
||||||
|
|
||||||
|
def expire_detections(self) -> None:
|
||||||
|
now = datetime.datetime.now().timestamp()
|
||||||
|
|
||||||
|
for detection in self.detections.values():
|
||||||
|
if now - detection["last_detection"] > 30:
|
||||||
|
detection["end_time"] = (
|
||||||
|
detection["last_detection"] + self.config.record.events.post_capture
|
||||||
|
)
|
||||||
|
self.queue.put(
|
||||||
|
(EventTypeEnum.audio, "end", self.config.name, detection)
|
||||||
|
)
|
||||||
|
|
||||||
def init_ffmpeg(self) -> None:
|
def init_ffmpeg(self) -> None:
|
||||||
try:
|
try:
|
||||||
@ -171,15 +192,12 @@ class AudioEventMaintainer(threading.Thread):
|
|||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
logger.error(f"Made the pipe")
|
|
||||||
|
|
||||||
self.audio_listener = sp.Popen(
|
self.audio_listener = sp.Popen(
|
||||||
self.ffmpeg_cmd,
|
self.ffmpeg_cmd,
|
||||||
stdout=sp.DEVNULL,
|
stdout=sp.DEVNULL,
|
||||||
stdin=sp.DEVNULL,
|
stdin=sp.DEVNULL,
|
||||||
start_new_session=True,
|
start_new_session=True,
|
||||||
)
|
)
|
||||||
logger.error(f"Started ffmpeg")
|
|
||||||
|
|
||||||
def read_audio(self) -> None:
|
def read_audio(self) -> None:
|
||||||
if self.pipe_file is None:
|
if self.pipe_file is None:
|
||||||
|
|||||||
@ -72,7 +72,7 @@ class EventProcessor(threading.Thread):
|
|||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
logger.debug(f"Event received: {event_type} {camera} {event_data['id']}")
|
logger.error(f"Event received: {source_type} {event_type} {camera} {event_data['id']}")
|
||||||
|
|
||||||
self.timeline_queue.put(
|
self.timeline_queue.put(
|
||||||
(
|
(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user