mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 07:35:27 +03:00
Use query parameters for the frame latest endpoint
This commit is contained in:
parent
6dadeeb488
commit
17788bb9c7
23
frigate/api/defs/media_query_parameters.py
Normal file
23
frigate/api/defs/media_query_parameters.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class Extension(str, Enum):
|
||||||
|
webp = "webp"
|
||||||
|
png = "png"
|
||||||
|
jpg = "jpg"
|
||||||
|
jpeg = "jpeg"
|
||||||
|
|
||||||
|
|
||||||
|
class MediaLatestFrameQueryParams(BaseModel):
|
||||||
|
extension: Extension = Extension.webp
|
||||||
|
bbox: Optional[int] = None
|
||||||
|
timestamp: Optional[int] = None
|
||||||
|
zones: Optional[int] = None
|
||||||
|
mask: Optional[int] = None
|
||||||
|
motion: Optional[int] = None
|
||||||
|
regions: Optional[int] = None
|
||||||
|
quality: Optional[int] = 70
|
||||||
|
height: Optional[int] = None
|
||||||
@ -15,6 +15,7 @@ import cv2
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import pytz
|
import pytz
|
||||||
from fastapi import APIRouter, Path, Query, Request, Response
|
from fastapi import APIRouter, Path, Query, Request, Response
|
||||||
|
from fastapi.params import Depends
|
||||||
from fastapi.responses import FileResponse, JSONResponse, StreamingResponse
|
from fastapi.responses import FileResponse, JSONResponse, StreamingResponse
|
||||||
from peewee import DoesNotExist, fn
|
from peewee import DoesNotExist, fn
|
||||||
from tzlocal import get_localzone_name
|
from tzlocal import get_localzone_name
|
||||||
@ -121,24 +122,18 @@ def camera_ptz_info(request: Request, camera_name: str):
|
|||||||
def latest_frame(
|
def latest_frame(
|
||||||
request: Request,
|
request: Request,
|
||||||
camera_name: str,
|
camera_name: str,
|
||||||
extension: Optional[str] = Query("webp", enum=["webp", "png", "jpg", "jpeg"]),
|
params: MediaLatestFrameQueryParams = Depends(),
|
||||||
bbox: Optional[int] = None,
|
|
||||||
timestamp: Optional[int] = None,
|
|
||||||
zones: Optional[int] = None,
|
|
||||||
mask: Optional[int] = None,
|
|
||||||
motion: Optional[int] = None,
|
|
||||||
regions: Optional[int] = None,
|
|
||||||
quality: Optional[int] = 70,
|
|
||||||
height: Optional[int] = None,
|
|
||||||
):
|
):
|
||||||
draw_options = {
|
draw_options = {
|
||||||
"bounding_boxes": bbox,
|
"bounding_boxes": params.bbox,
|
||||||
"timestamp": timestamp,
|
"timestamp": params.timestamp,
|
||||||
"zones": zones,
|
"zones": params.zones,
|
||||||
"mask": mask,
|
"mask": params.mask,
|
||||||
"motion_boxes": motion,
|
"motion_boxes": params.motion,
|
||||||
"regions": regions,
|
"regions": params.regions,
|
||||||
}
|
}
|
||||||
|
quality = params.quality
|
||||||
|
extension = params.extension
|
||||||
|
|
||||||
if camera_name in request.app.frigate_config.cameras:
|
if camera_name in request.app.frigate_config.cameras:
|
||||||
frame = request.app.detected_frames_processor.get_current_frame(
|
frame = request.app.detected_frames_processor.get_current_frame(
|
||||||
@ -163,7 +158,7 @@ def latest_frame(
|
|||||||
|
|
||||||
frame = request.app.camera_error_image
|
frame = request.app.camera_error_image
|
||||||
|
|
||||||
height = int(height or str(frame.shape[0]))
|
height = int(params.height or str(frame.shape[0]))
|
||||||
width = int(height * frame.shape[1] / frame.shape[0])
|
width = int(height * frame.shape[1] / frame.shape[0])
|
||||||
|
|
||||||
if frame is None:
|
if frame is None:
|
||||||
@ -459,7 +454,11 @@ def recordings(
|
|||||||
|
|
||||||
@router.get("/media/camera/{camera_name}/start/{start_ts}/end/{end_ts}/clip.mp4")
|
@router.get("/media/camera/{camera_name}/start/{start_ts}/end/{end_ts}/clip.mp4")
|
||||||
def recording_clip(
|
def recording_clip(
|
||||||
request: Request, camera_name: str, start_ts: float, end_ts: float, download: bool = False
|
request: Request,
|
||||||
|
camera_name: str,
|
||||||
|
start_ts: float,
|
||||||
|
end_ts: float,
|
||||||
|
download: bool = False,
|
||||||
):
|
):
|
||||||
recordings = (
|
recordings = (
|
||||||
Recordings.select(
|
Recordings.select(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user