diff --git a/frigate/http.py b/frigate/http.py index 44706f2c2..9c55d68c4 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -1118,6 +1118,15 @@ def latest_frame(camera_name): height = int(request.args.get("h", str(frame.shape[0]))) width = int(height * frame.shape[1] / frame.shape[0]) + if not frame: + return "Unable to get valid frame from {}".format(camera_name), 500 + + if height < 1 or width < 1: + return ( + "Invalid height / width requested :: {} / {}".format(height, width), + 400, + ) + frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA) ret, jpg = cv2.imencode( diff --git a/web/src/components/CameraImage.jsx b/web/src/components/CameraImage.jsx index 98754e506..ce4e4bef7 100644 --- a/web/src/components/CameraImage.jsx +++ b/web/src/components/CameraImage.jsx @@ -28,13 +28,18 @@ export default function CameraImage({ camera, onload, searchParams = '', stretch const scaledHeight = useMemo(() => { const scaledHeight = Math.floor(availableWidth / aspectRatio); - return stretch ? scaledHeight : Math.min(scaledHeight, height); + const finalHeight = stretch ? scaledHeight : Math.min(scaledHeight, height); + + if (finalHeight > 0) { + return finalHeight; + } + + return 100; }, [availableWidth, aspectRatio, height, stretch]); - const scaledWidth = useMemo(() => Math.ceil(scaledHeight * aspectRatio - scrollBarWidth), [ - scaledHeight, - aspectRatio, - scrollBarWidth, - ]); + const scaledWidth = useMemo( + () => Math.ceil(scaledHeight * aspectRatio - scrollBarWidth), + [scaledHeight, aspectRatio, scrollBarWidth] + ); const img = useMemo(() => new Image(), []); img.onload = useCallback( @@ -58,18 +63,16 @@ export default function CameraImage({ camera, onload, searchParams = '', stretch return (
- { - (enabled) ? - - :
Camera is disabled in config, no stream or snapshot available!
- } - { - (!hasLoaded && enabled) ? ( -
- -
- ) : null - } -
+ {enabled ? ( + + ) : ( +
Camera is disabled in config, no stream or snapshot available!
+ )} + {!hasLoaded && enabled ? ( +
+ +
+ ) : null} + ); }