From ba810ee2a8eba080657376d39c3c24b8b4107b24 Mon Sep 17 00:00:00 2001 From: tpjanssen <25168870+tpjanssen@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:08:34 +0100 Subject: [PATCH] Fix API latest image quality --- frigate/api/media.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/frigate/api/media.py b/frigate/api/media.py index e19fe547f..4e2627d35 100644 --- a/frigate/api/media.py +++ b/frigate/api/media.py @@ -134,6 +134,13 @@ def latest_frame( } quality = params.quality + if extension == "png": + quality_params = None + elif extension == "webp": + quality_params = [int(cv2.IMWRITE_WEBP_QUALITY), quality] + else: + quality_params = [int(cv2.IMWRITE_JPEG_QUALITY), quality] + if camera_name in request.app.frigate_config.cameras: frame = frame_processor.get_current_frame(camera_name, draw_options) retry_interval = float( @@ -174,7 +181,7 @@ def latest_frame( frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA) ret, img = cv2.imencode( - f".{extension}", frame, [int(cv2.IMWRITE_WEBP_QUALITY), quality] + f".{extension}", frame, quality_params ) return Response( content=img.tobytes(), @@ -193,7 +200,7 @@ def latest_frame( frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA) ret, img = cv2.imencode( - f".{extension}", frame, [int(cv2.IMWRITE_WEBP_QUALITY), quality] + f".{extension}", frame, quality_params ) return Response( content=img.tobytes(),