Backend and webui fixes (#11309)

* Ensure that items without end times are set to not have a snapshot

* Save full frame if no frame is currently saved

* Webui fixes

* Cleanup
This commit is contained in:
Nicolas Mowen 2024-05-09 07:20:33 -06:00 committed by GitHub
parent 4bcbf7435a
commit 4216d08099
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 5 deletions

View File

@ -683,9 +683,9 @@ class FrigateApp:
self.stop_event.set() self.stop_event.set()
# set an end_time on entries without an end_time before exiting # set an end_time on entries without an end_time before exiting
Event.update(end_time=datetime.datetime.now().timestamp()).where( Event.update(
Event.end_time == None end_time=datetime.datetime.now().timestamp(), has_snapshot=False
).execute() ).where(Event.end_time == None).execute()
ReviewSegment.update(end_time=datetime.datetime.now().timestamp()).where( ReviewSegment.update(end_time=datetime.datetime.now().timestamp()).where(
ReviewSegment.end_time == None ReviewSegment.end_time == None
).execute() ).execute()

View File

@ -110,6 +110,18 @@ class PendingReviewSegment:
self.frame_path, self.frame, [int(cv2.IMWRITE_WEBP_QUALITY), 60] self.frame_path, self.frame, [int(cv2.IMWRITE_WEBP_QUALITY), 60]
) )
def save_full_frame(self, camera_config: CameraConfig, frame):
color_frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420)
width = int(THUMB_HEIGHT * color_frame.shape[1] / color_frame.shape[0])
self.frame = cv2.resize(
color_frame, dsize=(width, THUMB_HEIGHT), interpolation=cv2.INTER_AREA
)
if self.frame is not None:
cv2.imwrite(
self.frame_path, self.frame, [int(cv2.IMWRITE_WEBP_QUALITY), 60]
)
def get_data(self, ended: bool) -> dict: def get_data(self, ended: bool) -> dict:
return { return {
ReviewSegment.id: self.id, ReviewSegment.id: self.id,
@ -273,8 +285,30 @@ class ReviewSegmentMaintainer(threading.Thread):
if segment.severity == SeverityEnum.alert and frame_time > ( if segment.severity == SeverityEnum.alert and frame_time > (
segment.last_update + THRESHOLD_ALERT_ACTIVITY segment.last_update + THRESHOLD_ALERT_ACTIVITY
): ):
if segment.frame is None:
try:
frame_id = f"{camera_config.name}{frame_time}"
yuv_frame = self.frame_manager.get(
frame_id, camera_config.frame_shape_yuv
)
segment.save_full_frame(camera_config, yuv_frame)
self.frame_manager.close(frame_id)
except FileNotFoundError:
return
self.end_segment(segment) self.end_segment(segment)
elif frame_time > (segment.last_update + THRESHOLD_DETECTION_ACTIVITY): elif frame_time > (segment.last_update + THRESHOLD_DETECTION_ACTIVITY):
if segment.frame is None:
try:
frame_id = f"{camera_config.name}{frame_time}"
yuv_frame = self.frame_manager.get(
frame_id, camera_config.frame_shape_yuv
)
segment.save_full_frame(camera_config, yuv_frame)
self.frame_manager.close(frame_id)
except FileNotFoundError:
return
self.end_segment(segment) self.end_segment(segment)
def check_if_new_segment( def check_if_new_segment(

View File

@ -204,8 +204,8 @@ export default function DynamicVideoPlayer({
/> />
<PreviewPlayer <PreviewPlayer
className={cn( className={cn(
isScrubbing || isLoading ? "visible" : "hidden",
className, className,
isScrubbing || isLoading ? "visible" : "hidden",
)} )}
camera={camera} camera={camera}
timeRange={timeRange} timeRange={timeRange}

View File

@ -25,7 +25,7 @@ export function useCameraPreviews(
const { data: allPreviews } = useSWR<Preview[]>( const { data: allPreviews } = useSWR<Preview[]>(
fetchPreviews fetchPreviews
? `preview/${camera}/start/${timeRange.after}/end/${timeRange.before}` ? `preview/${camera}/start/${Math.round(timeRange.after)}/end/${Math.round(timeRange.before)}`
: null, : null,
{ revalidateOnFocus: false, revalidateOnReconnect: false }, { revalidateOnFocus: false, revalidateOnReconnect: false },
); );