forked from Github/frigate
Respect motion only when playing back (#10632)
* Respect motion only when playing back motion * Increase efficiency * Fix import
This commit is contained in:
@@ -4,6 +4,8 @@ import {
|
||||
useMotionActivity,
|
||||
} from "@/api/ws";
|
||||
import { CameraConfig } from "@/types/frigateConfig";
|
||||
import { MotionData, ReviewSegment } from "@/types/review";
|
||||
import { TimeRange } from "@/types/timeline";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
type useCameraActivityReturn = {
|
||||
@@ -12,7 +14,7 @@ type useCameraActivityReturn = {
|
||||
activeAudio: boolean;
|
||||
};
|
||||
|
||||
export default function useCameraActivity(
|
||||
export function useCameraActivity(
|
||||
camera: CameraConfig,
|
||||
): useCameraActivityReturn {
|
||||
const [activeObjects, setActiveObjects] = useState<string[]>([]);
|
||||
@@ -66,3 +68,57 @@ export default function useCameraActivity(
|
||||
: false,
|
||||
};
|
||||
}
|
||||
|
||||
export function useCameraMotionTimestamps(
|
||||
timeRange: TimeRange,
|
||||
motionOnly: boolean,
|
||||
events: ReviewSegment[],
|
||||
motion: MotionData[],
|
||||
) {
|
||||
const timestamps = useMemo(() => {
|
||||
const seekableTimestamps = [];
|
||||
let lastEventIdx = 0;
|
||||
let lastMotionIdx = 0;
|
||||
|
||||
for (let i = timeRange.after; i <= timeRange.before; i += 0.5) {
|
||||
if (!motionOnly) {
|
||||
seekableTimestamps.push(i);
|
||||
} else {
|
||||
const relevantEventIdx = events.findIndex((seg, segIdx) => {
|
||||
if (segIdx < lastEventIdx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return seg.start_time <= i && seg.end_time >= i;
|
||||
});
|
||||
|
||||
if (relevantEventIdx != -1) {
|
||||
lastEventIdx = relevantEventIdx;
|
||||
continue;
|
||||
}
|
||||
|
||||
const relevantMotionIdx = motion.findIndex((mot, motIdx) => {
|
||||
if (motIdx < lastMotionIdx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mot.start_time <= i && mot.start_time + 15 >= i;
|
||||
});
|
||||
|
||||
if (relevantMotionIdx == -1 || motion[relevantMotionIdx].motion == 0) {
|
||||
if (relevantMotionIdx != -1) {
|
||||
lastMotionIdx = relevantMotionIdx;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
seekableTimestamps.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
return seekableTimestamps;
|
||||
}, [timeRange, motionOnly, events, motion]);
|
||||
|
||||
return timestamps;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user