mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-05-07 01:16:43 +02:00
Fix API latest image quality and API MIME types (#15964)
* Fix API latest image quality * Fix mime types * Code formatting + media_type fix
This commit is contained in:
parent
32c71c4108
commit
9983bd8d92
@ -133,6 +133,15 @@ def latest_frame(
|
|||||||
"regions": params.regions,
|
"regions": params.regions,
|
||||||
}
|
}
|
||||||
quality = params.quality
|
quality = params.quality
|
||||||
|
mime_type = extension
|
||||||
|
|
||||||
|
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]
|
||||||
|
mime_type = "jpeg"
|
||||||
|
|
||||||
if camera_name in request.app.frigate_config.cameras:
|
if camera_name in request.app.frigate_config.cameras:
|
||||||
frame = frame_processor.get_current_frame(camera_name, draw_options)
|
frame = frame_processor.get_current_frame(camera_name, draw_options)
|
||||||
@ -173,13 +182,11 @@ def latest_frame(
|
|||||||
|
|
||||||
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
|
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
|
||||||
|
|
||||||
ret, img = cv2.imencode(
|
ret, img = cv2.imencode(f".{extension}", frame, quality_params)
|
||||||
f".{extension}", frame, [int(cv2.IMWRITE_WEBP_QUALITY), quality]
|
|
||||||
)
|
|
||||||
return Response(
|
return Response(
|
||||||
content=img.tobytes(),
|
content=img.tobytes(),
|
||||||
media_type=f"image/{extension}",
|
media_type=f"image/{mime_type}",
|
||||||
headers={"Content-Type": f"image/{extension}", "Cache-Control": "no-store"},
|
headers={"Content-Type": f"image/{mime_type}", "Cache-Control": "no-store"},
|
||||||
)
|
)
|
||||||
elif camera_name == "birdseye" and request.app.frigate_config.birdseye.restream:
|
elif camera_name == "birdseye" and request.app.frigate_config.birdseye.restream:
|
||||||
frame = cv2.cvtColor(
|
frame = cv2.cvtColor(
|
||||||
@ -192,13 +199,11 @@ def latest_frame(
|
|||||||
|
|
||||||
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
|
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
|
||||||
|
|
||||||
ret, img = cv2.imencode(
|
ret, img = cv2.imencode(f".{extension}", frame, quality_params)
|
||||||
f".{extension}", frame, [int(cv2.IMWRITE_WEBP_QUALITY), quality]
|
|
||||||
)
|
|
||||||
return Response(
|
return Response(
|
||||||
content=img.tobytes(),
|
content=img.tobytes(),
|
||||||
media_type=f"image/{extension}",
|
media_type=f"image/{mime_type}",
|
||||||
headers={"Content-Type": f"image/{extension}", "Cache-Control": "no-store"},
|
headers={"Content-Type": f"image/{mime_type}", "Cache-Control": "no-store"},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
@ -241,6 +246,7 @@ def get_snapshot_from_recording(
|
|||||||
recording: Recordings = recording_query.get()
|
recording: Recordings = recording_query.get()
|
||||||
time_in_segment = frame_time - recording.start_time
|
time_in_segment = frame_time - recording.start_time
|
||||||
codec = "png" if format == "png" else "mjpeg"
|
codec = "png" if format == "png" else "mjpeg"
|
||||||
|
mime_type = "png" if format == "png" else "jpeg"
|
||||||
config: FrigateConfig = request.app.frigate_config
|
config: FrigateConfig = request.app.frigate_config
|
||||||
|
|
||||||
image_data = get_image_from_recording(
|
image_data = get_image_from_recording(
|
||||||
@ -257,7 +263,7 @@ def get_snapshot_from_recording(
|
|||||||
),
|
),
|
||||||
status_code=404,
|
status_code=404,
|
||||||
)
|
)
|
||||||
return Response(image_data, headers={"Content-Type": f"image/{format}"})
|
return Response(image_data, headers={"Content-Type": f"image/{mime_type}"})
|
||||||
except DoesNotExist:
|
except DoesNotExist:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
Loading…
Reference in New Issue
Block a user