Send error image when camera stream is not available

This commit is contained in:
Nick Mowen 2022-11-28 13:48:42 -07:00
parent dff477d548
commit 1d648ed605
4 changed files with 14 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import base64 import base64
from datetime import datetime, timedelta from datetime import datetime, timedelta
import copy import copy
import glob
import logging import logging
import json import json
import os import os
@ -657,8 +658,15 @@ def latest_frame(camera_name):
frame = current_app.detected_frames_processor.get_current_frame( frame = current_app.detected_frames_processor.get_current_frame(
camera_name, draw_options camera_name, draw_options
) )
if frame is None:
frame = np.zeros((720, 1280, 3), np.uint8) if frame is None or datetime.now().timestamp() > (
current_app.detected_frames_processor.get_current_frame_time(camera_name)
+ 10
):
error_image = glob.glob("/opt/frigate/frigate/images/camera-error.jpg")
if len(error_image) > 0:
frame = cv2.imread(error_image[0], cv2.IMREAD_UNCHANGED)
height = int(request.args.get("h", str(frame.shape[0]))) height = int(request.args.get("h", str(frame.shape[0])))
width = int(height * frame.shape[1] / frame.shape[0]) width = int(height * frame.shape[1] / frame.shape[0])

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

View File

@ -882,6 +882,10 @@ class TrackedObjectProcessor(threading.Thread):
def get_current_frame(self, camera, draw_options={}): def get_current_frame(self, camera, draw_options={}):
return self.camera_states[camera].get_current_frame(draw_options) return self.camera_states[camera].get_current_frame(draw_options)
def get_current_frame_time(self, camera) -> int:
"""Returns the latest frame time for a given camera."""
return self.camera_states[camera].current_frame_time
def run(self): def run(self):
while not self.stop_event.is_set(): while not self.stop_event.is_set():
try: try:

View File

@ -7,7 +7,6 @@ import queue
import signal import signal
import subprocess as sp import subprocess as sp
import threading import threading
from multiprocessing import shared_memory
from wsgiref.simple_server import make_server from wsgiref.simple_server import make_server
import cv2 import cv2